pub trait Zero {
const ZERO: Self;
}Expand description
Numeric constants traits for primitive numeric types
use generic_constants::OneHundredTwentySeven;
fn saturate_to_127<T: OneHundredTwentySeven + Ord>(value: T) -> T {
if value > T::ONE_HUNDRED_TWENTY_SEVEN {
T::ONE_HUNDRED_TWENTY_SEVEN
} else {
value
}
}
fn main() {
assert_eq!(saturate_to_127(200u32), 127u32);
assert_eq!(saturate_to_127(50u32), 50u32);
}Required Associated Constants§
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.