nonmax
nonmax copied to clipboard
Rust crate that provides number types similar to std's NonZero* types, but that cannot hold a type's maximum value instead.
This PR starts off by splitting the fundamental structure and functions into two different macros, to allow for a custom definition of the internals without having to rewrite all the...
It seems like the nonmax types are missing `TryFrom` implementations from larger integer sizes, eg: `TryFrom for NonMaxU32`.
It would be possible (maybe slightly cursed?) to implement `NonMaxU32` (and larger) in terms of some stable standard library type that already has a niche at `u32::MAX`, removing the run-time...
Adds all possible TryFrom implementations and applicable From implementations involving nonmaxes and primitives. Also has conditional compilation to optimize conversions involving *size types. This does have a relatively large impact...
closes #22 I think this should be a non-breaking change since there are type-aliases to all the existing names, i.e. ``` pub type NonMaxU8 = NonMax; ``` Might be possible...
The standard library now has a generic `NonZero`, so one can write, e.g. `NonZero` instead of `NonZeroU32`, and [it seems the former is considered the better way of doing things](https://github.com/rust-lang/rust/issues/82363#issuecomment-921513910)....
Adds a macro for each of the integer types to allow construction of the `NonMaxXX` type using compile time checking. # Example ```rust let _ = nonmax_u8!(254); // works let...