#integer #statically #checked #non-zero-usize

macro nonzero

Statically checked non-zero integers

2 unstable releases

0.2.0 Aug 23, 2023
0.1.0 Jul 24, 2021

#2117 in Rust patterns

Download history 742/week @ 2025-04-09 998/week @ 2025-04-16 718/week @ 2025-04-23 675/week @ 2025-04-30 995/week @ 2025-05-07 832/week @ 2025-05-14 666/week @ 2025-05-21 689/week @ 2025-05-28 604/week @ 2025-06-04 864/week @ 2025-06-11 1096/week @ 2025-06-18 809/week @ 2025-06-25 618/week @ 2025-07-02 754/week @ 2025-07-09 572/week @ 2025-07-16 517/week @ 2025-07-23

2,615 downloads per month
Used in 3 crates (2 directly)

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

~250–720KB
~16K SLoC