#nonzero #int #const #literal #non-zero

no-std nonzero_lit

Easy, safe, and fully zero-cost NonZero constants and literals

3 releases

0.1.2 May 3, 2021
0.1.1 May 3, 2021
0.1.0 May 2, 2021

#1111 in Rust patterns

Download history 103/week @ 2022-11-26 89/week @ 2022-12-03 106/week @ 2022-12-10 93/week @ 2022-12-17 36/week @ 2022-12-24 126/week @ 2022-12-31 98/week @ 2023-01-07 107/week @ 2023-01-14 360/week @ 2023-01-21 73/week @ 2023-01-28 186/week @ 2023-02-04 259/week @ 2023-02-11 80/week @ 2023-02-18 209/week @ 2023-02-25 109/week @ 2023-03-04 54/week @ 2023-03-11

481 downloads per month

MIT OR Apache-2.0 OR CC0-1.0

26KB
167 lines

nonzero_lit

Build Status Docs Latest Version Minimum Rust Version

A small macro crate providing safe, easy, and fully zero-cost way to construct constant or literal instances of the NonZero* types from core::num.

Features

Usage

Add this to your Cargo.toml:

[dependencies]
nonzero_lit = "0.1"

Examples

let x = nonzero_lit::i32!(4);
assert_eq!(x.get(), 4);
const FERRIS: core::num::NonZeroU32 = nonzero_lit::u32!(0xf34415);
assert_eq!(FERRIS.get(), 0xf34415);
const FERRIS: core::num::NonZeroU32 = nonzero_lit::u32!(0xf34415);
assert_eq!(FERRIS.get(), 0xf34415);

License

Public domain, as explained here. If that's unacceptable, it's also available under either the Apache-2.0 or MIT licenses, at your option.

No runtime deps