Macro nonzero_lit::isize[][src]

macro_rules! isize {
    ($val:expr $(,)?) => { ... };
}

Create a literal NonZeroIsize.

Examples

Basic usage

let x = nonzero_lit::isize!(4);
assert_eq!(x.get(), 4);

Works for consts, and the parameter can be any const expression (not just a literal).

const A: isize = 5;
const B: core::num::NonZeroIsize = nonzero_lit::isize!(A * 10);
assert_eq!(B.get(), 50);

Misuse is detected at compile time.

const ZERO: core::num::NonZeroIsize = nonzero_lit::isize!(0);

Even if dodgy code tries to #[allow(...)] it.

#[allow(const_err)]
const ZERO: core::num::NonZeroIsize = nonzero_lit::isize!(0);

Note: argument must be a constant expression.

let bar = 3;
let foo = nonzero_lit::isize!(bar);