pub trait Truncate: Sealed + Sized {
// Required method
fn truncate<T: TruncateFrom<Self>>(self) -> T;
}Expand description
Trait to truncate an integer from a larger size.
This is better than as casting because:
- It is explicitly a truncating operation, and will only truncate
- It only supports similar signs, i/e
u16toi8will not compile - It is method chainable
- You can use turbofishy or type inference :D
Error messages should also be clear in the event of an invalid operation, so you will not be left wondering what went wrong, this is mostly thanks to rusts great error messages though
Required Methods§
Sourcefn truncate<T: TruncateFrom<Self>>(self) -> T
fn truncate<T: TruncateFrom<Self>>(self) -> T
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.