pub trait TryFromDigits<T> {
// Required method
fn from_digits(n: T) -> Result<Self, <Self as TryFrom<T>>::Error>
where Self: TryFrom<T>;
}Expand description
Generic trait for converting integer type digits to some integer type.
- Returns an error if the value is out of range.
§Usage
Basic use of the trait.
use num_convert::TryFromDigits;
assert_eq!(<u8 as TryFromDigits<u16>>::from_digits(65_255_u16), Ok(255_u8));
assert_eq!(<u8 as TryFromDigits<u32>>::from_digits(100_000_u32), Ok(0_u8));§Examples
assert_eq!(<u16>::from_digits(10_000_965_535_i64), Ok(65_535_u16));
assert!(<u8>::from_digits(10_000_000_256_u64).is_err());