| Crates.io | nonzero |
| lib.rs | nonzero |
| version | 0.2.0 |
| created_at | 2021-07-24 22:48:29.357821+00 |
| updated_at | 2023-08-23 02:26:14.235842+00 |
| description | Statically checked non-zero integers |
| homepage | https://github.com/jerry73204/nonzero |
| repository | https://github.com/jerry73204/nonzero.git |
| max_upload_size | |
| id | 426922 |
| size | 9,198 |
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.
use nonzero::nonzero as nz;
use std::num::{NonZeroI32, NonZeroUsize};
let safe_seven: NonZeroUsize = nz!(7usize);
let negative_one: NonZeroI32 = nz!(-1i32);
MIT license. See license file.