Macro nonzero_lit::i32[][src]

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

Create a literal NonZeroI32.

Examples

Basic usage

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

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

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

Misuse is detected at compile time.

const ZERO: core::num::NonZeroI32 = nonzero_lit::i32!(0);

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

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

Note: argument must be a constant expression.

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