devela/num/unit/
helpers.rs
1macro_rules! impl_try_from {
5 ($unit:ty, $from_prim:ty => $($to_prim:ty),+) => {
6 $( impl_try_from![@$unit, $from_prim => $to_prim]; )+
7 };
8
9 (@$unit:ty, $from_prim:ty => $to_prim:ty) => {
10 #[cfg(feature = "cast")]
11 #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "cast")))]
12 impl TryFrom<$unit> for $to_prim {
13 type Error = $crate::num::NumError;
14 fn try_from(from: $unit) -> Result<$to_prim, Self::Error> { crate::paste! {
15 $crate::num::Cast($from_prim::from(from)).[< checked_cast_to_ $to_prim>]()
16 }}
17 }
18 };
19}
20pub(super) use impl_try_from;