pub trait MinMaxNum: PartialOrd + Add + Sub + Copy {
    const MIN_VALUE: Self;
    const MAX_VALUE: Self;
}
Expand description

Define maximum number a generic T can hold. This is implemented for all integer and float primitive types

Example
// The function with the enforced constraint
fn foo<T: MustBeInRange>(bar: T) {
    // Use T as needed
    println!("Input: {:?}", bar);
}

foo(42u64);
foo(0u64);
foo(std::u64::MAX);

Required Associated Constants§

source

const MIN_VALUE: Self

The minimum value that can be defined

source

const MAX_VALUE: Self

The maximum value that can be defined

Implementations on Foreign Types§

source§

impl MinMaxNum for i32

source§

const MIN_VALUE: i32 = -2_147_483_648i32

source§

const MAX_VALUE: i32 = 2_147_483_647i32

source§

impl MinMaxNum for f32

source§

const MIN_VALUE: f32 = -3.40282347E+38f32

source§

const MAX_VALUE: f32 = 3.40282347E+38f32

source§

impl MinMaxNum for u64

source§

const MIN_VALUE: u64 = 0u64

source§

const MAX_VALUE: u64 = 18_446_744_073_709_551_615u64

source§

impl MinMaxNum for i8

source§

const MIN_VALUE: i8 = -128i8

source§

const MAX_VALUE: i8 = 127i8

source§

impl MinMaxNum for f64

source§

const MIN_VALUE: f64 = -1.7976931348623157E+308f64

source§

const MAX_VALUE: f64 = 1.7976931348623157E+308f64

source§

impl MinMaxNum for u128

source§

const MIN_VALUE: u128 = 0u128

source§

const MAX_VALUE: u128 = 340_282_366_920_938_463_463_374_607_431_768_211_455u128

source§

impl MinMaxNum for u8

source§

const MIN_VALUE: u8 = 0u8

source§

const MAX_VALUE: u8 = 255u8

source§

impl MinMaxNum for i64

source§

const MIN_VALUE: i64 = -9_223_372_036_854_775_808i64

source§

const MAX_VALUE: i64 = 9_223_372_036_854_775_807i64

source§

impl MinMaxNum for u32

source§

const MIN_VALUE: u32 = 0u32

source§

const MAX_VALUE: u32 = 4_294_967_295u32

source§

impl MinMaxNum for i16

source§

const MIN_VALUE: i16 = -32_768i16

source§

const MAX_VALUE: i16 = 32_767i16

source§

impl MinMaxNum for u16

source§

const MIN_VALUE: u16 = 0u16

source§

const MAX_VALUE: u16 = 65_535u16

source§

impl MinMaxNum for i128

source§

const MIN_VALUE: i128 = -170_141_183_460_469_231_731_687_303_715_884_105_728i128

source§

const MAX_VALUE: i128 = 170_141_183_460_469_231_731_687_303_715_884_105_727i128

Implementors§