Expand description
Compile-time checked non-zero integers with type inference and first-class const support.
const UNSIGNED: NonZeroUsize = nonzero!(1);
const SIGNED: NonZeroI8 = nonzero!(-1);
// ^ correctly infers return type
const MY_CONST: usize = 20;
const MY_NONZERO_CONST: NonZeroUsize = nonzero!(MY_CONST - 19);
// refer to other constant values ^ⓘ
let runtime = nonzero!(0); // eager evaluation§Comparison with other libraries
nonzerouses a proc-macro that parses the expression passed to it, precluding- Type inference.
- Referencing constants.
Macros§
- nonzero
- Evaluate the given
exprat compile time, asserting that it is non-zero, returning a (usually inferred) type-safe non-zero item.