Skip to main content

nz

Function nz 

Source
pub const fn nz(value: usize) -> NonZero<usize>
Expand description

Returns a NonZeroUsize from a known non-zero compile-time constant.

This helper panics during const evaluation when value is zero, surfacing the violation at build time. At runtime it remains a single conditional branch that the compiler folds away for constant inputs, eliminating the unsafe { NonZeroUsize::new_unchecked(...) } ceremony every concrete codec otherwise repeats.

§Parameters

  • value: Non-zero item count.

§Returns

Returns a NonZeroUsize equal to value.

§Panics

Panics when value is zero.