Skip to main content

nz

Macro nz 

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

Builds a NonZeroUsize from a literal or constant expression.

Ergonomic shorthand for the NonZeroUsize::new(N).expect(..) pattern at call sites that know the value is non-zero by construction (tests, examples, benchmarks). Use this whenever passing literal step or simulation counts to one of the public pricing kernels migrated in #337.

§Panics

Panics with a descriptive message if $val evaluates to zero. For runtime values coming from JSON, CLI, or external APIs prefer NonZeroUsize::new(x).ok_or_else(..) at the boundary instead.

§Examples

use optionstratlib_core::nz;
use std::num::NonZeroUsize;

let steps = nz!(100);
assert_eq!(steps.get(), 100);