Trait polkadot_sdk_frame::traits::DefensiveMax
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§
fn defensive_max(self, other: T) -> Self
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);
fn defensive_strict_max(self, other: T) -> Self
fn defensive_strict_max(self, other: T) -> Self
Object Safety§
This trait is not object safe.