Trait frame_support::traits::DefensiveMax

source ·
pub trait DefensiveMax<T> {
    // Required methods
    fn defensive_max(self, other: T) -> Self;
    fn defensive_strict_max(self, other: T) -> Self;
}
Expand description

Defensively calculates the maximum of two values.

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

Required Methods§

source

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

Returns the maximum and defensively asserts that other is not larger than self.

§Example
use frame_support::traits::DefensiveMax;
// max(4, 3) is 4.
assert_eq!(4, 4_u32.defensive_max(3_u32));
// max(4, 4) is 4.
assert_eq!(4, 4_u32.defensive_max(4_u32));
use frame_support::traits::DefensiveMax;
// max(4, 5) panics.
4_u32.defensive_max(5_u32);
source

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

Returns the maximum and defensively asserts that other is smaller than self.

§Example
use frame_support::traits::DefensiveMax;
// y(4, 3) is 4.
assert_eq!(4, 4_u32.defensive_strict_max(3_u32));
use frame_support::traits::DefensiveMax;
// max(4, 4) panics.
4_u32.defensive_strict_max(4_u32);

Object Safety§

This trait is not object safe.

Implementors§

source§

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