Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::convert::TryFrom;
- struct Numeric(u64);
- enum SomeType {
- Numeric(Numeric),
- }
- macro_rules! impl_try_from {
- ($ty:ty) => {
- impl TryFrom<$ty> for SomeType {
- type Error = <u64 as TryFrom<$ty>>::Error;
- fn try_from(n: $ty) -> Result<Self, Self::Error> {
- u64::try_from(n).map(|n| SomeType::Numeric(Numeric(n)))
- }
- }
- };
- }
- impl_try_from!(u8);
- impl_try_from!(u16);
- impl_try_from!(u32);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement