Trait num_convert::TryIntoByAdd
source · pub trait TryIntoByAdd<T> {
// Required method
fn try_into_by_add(self) -> Option<T>;
}Expand description
A generic trait for converting into possible types.
Examples
Usage:
fn convert_try_into_u8<T: TryIntoByAdd<u8>>(min: T, max: T) -> (u8, u8) {
(min.try_into_by_add().unwrap(), max.try_into_by_add().unwrap())
}
assert_eq!(convert_try_into_u8(i8::MIN, i8::MAX), (u8::MIN, u8::MAX));
assert_eq!(TryIntoByAdd::<u8>::try_into_by_add(127_i16), Some(255u8));
assert_eq!(TryIntoByAdd::<u8>::try_into_by_add(128_i16), None);
assert_eq!(TryIntoByAdd::<u8>::try_into_by_add(-128_i16), Some(0_u8));
assert_eq!(TryIntoByAdd::<u8>::try_into_by_add(-129_i16), None);Required Methods§
sourcefn try_into_by_add(self) -> Option<T>
fn try_into_by_add(self) -> Option<T>
Converts the value of self to an T.