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