#literals #non-zero #const #int #compile-time

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

#8 in #non-zero

Download history 139/week @ 2024-06-07 207/week @ 2024-06-14 172/week @ 2024-06-21 234/week @ 2024-06-28 114/week @ 2024-07-05 237/week @ 2024-07-12 136/week @ 2024-07-19 192/week @ 2024-07-26 256/week @ 2024-08-02 319/week @ 2024-08-09 225/week @ 2024-08-16 179/week @ 2024-08-23 358/week @ 2024-08-30 325/week @ 2024-09-06 198/week @ 2024-09-13 173/week @ 2024-09-20

1,089 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