#non-zero #literals #const #int

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

#1863 in Rust patterns

Download history 77/week @ 2023-12-06 150/week @ 2023-12-13 164/week @ 2023-12-20 210/week @ 2023-12-27 430/week @ 2024-01-03 829/week @ 2024-01-10 894/week @ 2024-01-17 655/week @ 2024-01-24 511/week @ 2024-01-31 449/week @ 2024-02-07 523/week @ 2024-02-14 398/week @ 2024-02-21 638/week @ 2024-02-28 408/week @ 2024-03-06 615/week @ 2024-03-13 320/week @ 2024-03-20

2,020 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