pub trait FromAs<T> {
// Required method
fn from_as(n: T) -> Self;
}Expand description
The FromAs generic trait for convert from value between integer types with possible overflow.
- Can use conversion with overflow in generic code.
§Usage
Basic use of the trait.
use num_convert::FromAs;
assert_eq!(<u8 as FromAs<i8>>::from_as(-128_i8), 128_u8);
assert_eq!(<i8>::from_as(128_u8), -128_i8);§Examples
assert_eq!(<u8>::from_as(258_u16), 2_u8);
assert_eq!(<u8 as FromAs<u16>>::from_as(255_u16), 255_u8);Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.