Provides the nz macro for constructing a
std::num::NonZero* from an integer constant.
Example
Usage
use nz;
use NonZeroU64;
let two = nz!; // returns a `NonZeroU16`
assert_eq!;
// infers the argument's type from the returned `NonZero`
const THREE: NonZeroU64 = nz!;
assert_eq!;
const FOUR: i8 = -4;
let fourz = nz!; // returns a `NonZeroI8`
assert_eq!;
Zero argument
#![feature(inline_const)]
const ZERO: u8 = 0;
let _ = notzero::nz!(ZERO);
the above code produces this compile-time error:
error[E0080]: evaluation of `main::_doctest_main_src_lib_rs_27_0::{constant#0}` failed
--> src/lib.rs:32:9
|
8 | let _ = notzero::nz!(ZERO);
| ^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'passed in a `0` argument', src/lib.rs:8:9
|
= note: this error originates in the macro `notzero::nz` (in Nightly builds, run with -Z macro-backtrace for more info)
No-std support
notzero is #![no_std], it can be used anywhere Rust can be used.
Minimum Supported Rust Version
This crate currently requires users to enable the inline_const unstable feature,
which means that it requires the nightly compiler.
This crate will support stable Rust once inline_const stabilizes,
requiring only the Rust version where the feature is stabilized.