Expand description
nonmax provides types similar to the std NonZero*
types, but instead requires
that their values are not the maximum for their type. This ensures that
Option<NonMax*>
is no larger than NonMax*
.
nonmax supports every type that has a corresponding non-zero variant in the standard library:
NonMaxI8
NonMaxI16
NonMaxI32
NonMaxI64
NonMaxI128
NonMaxIsize
NonMaxU8
NonMaxU16
NonMaxU32
NonMaxU64
NonMaxU128
NonMaxUsize
§Example
use nonmax::{NonMaxI16, NonMaxU8};
let value = NonMaxU8::new(16).expect("16 should definitely fit in a u8");
assert_eq!(value.get(), 16);
assert_eq!(std::mem::size_of_val(&value), 1);
let signed = NonMaxI16::new(i16::min_value()).expect("minimum values are fine");
assert_eq!(signed.get(), i16::min_value());
assert_eq!(std::mem::size_of_val(&signed), 2);
let oops = NonMaxU8::new(255);
assert_eq!(oops, None);
§Features
std
(default): implementsstd::error::Error
forParseIntError
andTryFromIntError
. Disable this feature for#![no_std]
support.
§Minimum Supported Rust Version (MSRV)
nonmax supports Rust 1.47.0 and newer. Until this library reaches 1.0, changes to the MSRV will require major version bumps. After 1.0, MSRV changes will only require minor version bumps, but will need significant justification.
Structs§
- NonMax
I8 - An integer that is known not to equal its maximum value.
- NonMax
I16 - An integer that is known not to equal its maximum value.
- NonMax
I32 - An integer that is known not to equal its maximum value.
- NonMax
I64 - An integer that is known not to equal its maximum value.
- NonMax
I128 - An integer that is known not to equal its maximum value.
- NonMax
Isize - An integer that is known not to equal its maximum value.
- NonMax
U8 - An integer that is known not to equal its maximum value.
- NonMax
U16 - An integer that is known not to equal its maximum value.
- NonMax
U32 - An integer that is known not to equal its maximum value.
- NonMax
U64 - An integer that is known not to equal its maximum value.
- NonMax
U128 - An integer that is known not to equal its maximum value.
- NonMax
Usize - An integer that is known not to equal its maximum value.
- Parse
IntError - An error type returned when an integer cannot be parsed (mimics std::num::ParseIntError)
- TryFrom
IntError - An error type returned when a checked integral type conversion fails (mimics std::num::TryFromIntError)