macro nonzero

Statically checked non-zero integers

2 unstable releases

0.2.0 Aug 23, 2023
0.1.0 Jul 24, 2021
Download history 557/week @ 2024-07-23 931/week @ 2024-07-30 622/week @ 2024-08-06 812/week @ 2024-08-13 339/week @ 2024-08-20 410/week @ 2024-08-27 417/week @ 2024-09-03 644/week @ 2024-09-10 462/week @ 2024-09-17 779/week @ 2024-09-24 563/week @ 2024-10-01 562/week @ 2024-10-08 411/week @ 2024-10-15 361/week @ 2024-10-22 369/week @ 2024-10-29 475/week @ 2024-11-05

1,721 downloads per month
Used in 2 crates (via fusion-blossom)

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.3–0.8MB
~18K SLoC