nz (non-zero)

The nz crate provides a collection of user-friendly macros that simplify the creation of new instances of non-zero numeric types found in the [core::num]. With these macros, you can effortlessly generate instances using numeric literals, constant values and constant expressions, all at compile time.

Features

NonZero macros

| Type | Macro | |------|-------| | NonZeroI8 | nz::i8! | | NonZeroI16 | nz::i16! | | NonZeroI32 | nz::i32! | | NonZeroI64 | nz::i64! | | NonZeroI128 | nz::i128! | | NonZeroIsize | nz::isize! | | NonZeroU8 | nz::u8! | | NonZeroU16 | nz::u16! | | NonZeroU32 | nz::u32! | | NonZeroU64 | nz::u64! | | NonZeroU128 | nz::u128! | | NonZeroUsize | nz::usize! |

Basic usage

```rust use core::num::NonZeroU8;

const NZU8MIN: NonZeroU8 = nz::u8!(1); // with numeric literal const NZU8MAX: NonZeroU8 = nz::u8!(u8::MAX); // with constant value let sum = nz::u8!(NZU8MAX.get() & NZU8MIN.get() + 7); // with constant expression ```

Remarks

Non-zero macros cannot be used with constant function arguments as they are not constant values.

Example

```rust, compile_fail use core::num::NonZeroU64;

const fn wrappingaddnz(a: u64, b: NonZeroU64) -> NonZeroU64 { // a and b is not constant nz::u64!(a.wrappingadd(b.get())) // <- cause of the compile error } let nz = wrappingadd_nz(2, nz::u64!(1)); ```