Skip to main content

nz

Macro nz 

Source
macro_rules! nz {
    ($value:expr) => { ... };
}
Expand description

Const-friendly wrapper around nz for use in expression position.

Prefer this macro over unsafe { NonZeroUsize::new_unchecked(...) } in Codec::min_units_per_value / max_units_per_value and similar sites where the item count is a compile-time constant: the panic branch is folded away and the call expands to a NonZeroUsize value the compiler can prove is non-zero.

§Examples

use qubit_io::nz;
const MAX: core::num::NonZeroUsize = qubit_io::nz!(4);