referrerpolicy=no-referrer-when-downgrade

Trait frame_support::traits::DefensiveMin

source ·
pub trait DefensiveMin<T> {
    // Required methods
    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§

source

fn defensive_min(self, other: T) -> Self

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);
source

fn defensive_strict_min(self, other: T) -> Self

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);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> DefensiveMin<T> for T
where T: PartialOrd<T>,