2 unstable releases

0.2.0 Aug 23, 2023
0.1.0 Jul 24, 2021
Download history 28/week @ 2023-06-09 48/week @ 2023-06-16 9/week @ 2023-06-23 7/week @ 2023-06-30 5/week @ 2023-07-07 4/week @ 2023-07-14 6/week @ 2023-07-21 5/week @ 2023-07-28 15/week @ 2023-08-04 5/week @ 2023-08-11 92/week @ 2023-08-18 144/week @ 2023-08-25 103/week @ 2023-09-01 133/week @ 2023-09-08 115/week @ 2023-09-15 125/week @ 2023-09-22

506 downloads per month

MIT license

7KB
167 lines

nonzero: Statically Checked Non-Zero Integers

The crate provides the nonzero! macro that converts an integer to NonZero{Usize,Isize,...} types. The conversion is done statically without extra runtime cost, and rejects zeros in compile-time.

[ docs.rs | crates.io ]

Example

use nonzero::nonzero as nz;
use std::num::{NonZeroI32, NonZeroUsize};

let safe_seven: NonZeroUsize = nz!(7usize);
let negative_one: NonZeroI32 = nz!(-1i32);

License

MIT license. See license file.

Dependencies

~0.5–1MB
~22K SLoC