Skip to main content

Crate arithmetic_nonmax

Crate arithmetic_nonmax 

Source
Expand description

NonMax provides integer types that cannot be the maximum value of their underlying primitive type.

§Memory Optimization

The main benefit of NonMax<T> is that Option<NonMax<T>> has the same size as T. This is achieved through Rust’s “niche optimization”, where the bit pattern of the maximum value is used to represent None.

Primitivesize_of::<T>()size_of::<Option<T>>()size_of::<Option<NonMax<T>>>()
u32484
i32484
u8121

Structs§

MaxValueError
Error type returned when a value is the maximum for its type.
NonMax
A wrapper type for an integer that cannot be its maximum value.

Type Aliases§

NonMaxI8
A signed 8-bit integer that cannot be i8::MAX.
NonMaxI16
A signed 16-bit integer that cannot be i16::MAX.
NonMaxI32
A signed 32-bit integer that cannot be i32::MAX.
NonMaxI64
A signed 64-bit integer that cannot be i64::MAX.
NonMaxI128
A signed 128-bit integer that cannot be i128::MAX.
NonMaxIsize
A signed pointer-sized integer that cannot be isize::MAX.
NonMaxU8
An unsigned 8-bit integer that cannot be u8::MAX.
NonMaxU16
An unsigned 16-bit integer that cannot be u16::MAX.
NonMaxU32
An unsigned 32-bit integer that cannot be u32::MAX.
NonMaxU64
An unsigned 64-bit integer that cannot be u64::MAX.
NonMaxU128
An unsigned 128-bit integer that cannot be u128::MAX.
NonMaxUsize
An unsigned pointer-sized integer that cannot be usize::MAX.