#[macro_export]
macro_rules! impl_try_from_le32_for_enumn {
($ty:ty, $name:literal) => {
impl TryFrom<Le32> for $ty {
type Error = ReadCmdError;
fn try_from(x: Le32) -> Result<Self, Self::Error> {
let v: u32 = x.into();
Self::n(v).ok_or_else(|| {
error!(concat!("invalid ", $name, ": {}"), v);
ReadCmdError::InvalidArgument
})
}
}
};
}
#[macro_export]
macro_rules! impl_from_for_interconvertible_structs {
($t1:ident, $t2:ident, $($v:ident),+) => {
impl_from_for_interconvertible_structs_core!($t1, $t2, $( $v ),+ );
impl_from_for_interconvertible_structs_core!($t2, $t1, $( $v ),+ );
};
}
macro_rules! impl_from_for_interconvertible_structs_core {
($t1:ident, $t2:ident, $($v:ident),+) => {
impl From<$t1> for $t2 {
#[allow(clippy::needless_update)]
fn from(x :$t1) -> Self {
$t2 {
$( $v: x.$v.into(), )+
..Default::default() }
}
}
};
}