pub trait DefensiveMin<T> {
    fn defensive_min(self, other: T) -> Self;
    fn defensive_strict_min(self, other: T) -> Self;
}
Expand description

Defensively calculates the minimum of two values.

Can be used in contexts where we assume the receiver value to be (strictly) smaller.

Required Methods§

Returns the minimum and defensively checks that self is not larger than other.

Example
use frame_support::traits::DefensiveMin;
// min(3, 4) is 3.
assert_eq!(3, 3_u32.defensive_min(4_u32));
// min(4, 4) is 4.
assert_eq!(4, 4_u32.defensive_min(4_u32));
use frame_support::traits::DefensiveMin;
// min(4, 3) panics.
4_u32.defensive_min(3_u32);

Returns the minimum and defensively checks that self is smaller than other.

Example
use frame_support::traits::DefensiveMin;
// min(3, 4) is 3.
assert_eq!(3, 3_u32.defensive_strict_min(4_u32));
use frame_support::traits::DefensiveMin;
// min(4, 4) panics.
4_u32.defensive_strict_min(4_u32);

Implementors§