Macro nonzero_lit::i8[][src]

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

Create a literal NonZeroI8.

Examples

Basic usage

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

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

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

Misuse is detected at compile time.

const ZERO: core::num::NonZeroI8 = nonzero_lit::i8!(0);

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

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

Note: argument must be a constant expression.

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