1 macro_rules! validated_fields {
3 #[fields_ty = $fields_ty:ident]
5 $vis:vis struct $ty:ident $body:tt
8 #[derive(::serde::Serialize, ::serde::Deserialize)]
9 $vis struct $fields_ty $body
12 $vis struct $ty($fields_ty);
14 impl TryFrom<$fields_ty> for $ty {
15 type Error = crate::error::Error;
17 fn try_from(fields: $fields_ty) -> Result<Self, Self::Error> {
22 impl From<$ty> for $fields_ty {
23 fn from(value: $ty) -> Self {
28 impl ::std::ops::Deref for $ty {
29 type Target = $fields_ty;
31 fn deref(&self) -> &Self::Target {
37 $vis const fn get(&self) -> &$fields_ty {
42 impl ::serde::Serialize for $ty {
43 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
45 S: ::serde::Serializer,
47 self.0.serialize(serializer)
51 impl<'de> ::serde::Deserialize<'de> for $ty {
52 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
54 D: ::serde::Deserializer<'de>,
56 $fields_ty::deserialize(deserializer)?
58 .map_err(<D::Error as ::serde::de::Error>::custom)
64 macro_rules! const_unwrap_opt {
65 ($v:expr $(, $($msg:literal $(,)?)?)?) => {
68 None => panic!(concat!("tried to unwrap None", $($(": ", $msg,)?)?)),
73 macro_rules! const_unwrap_res {
74 ($v:expr $(, $($msg:literal $(,)?)?)?) => {
77 Err(_e) => panic!(concat!("tried to unwrap Err", $($(": ", $msg,)?)?)),
82 macro_rules! const_try {
83 ($v:expr, Err($var:ident) => Err($err:expr) $(,)?) => {
86 Err($var) => return Err($err),
92 Err(e) => return Err(e),
97 macro_rules! nzu32_lit {
99 const V: NonZeroU32 = match NonZeroU32::new($v) {
101 None => panic!("literal must not be zero"),