nonn

Crates.iononn
lib.rsnonn
version0.1.4
sourcesrc
created_at2023-08-27 16:19:22.570779
updated_at2023-08-29 10:46:29.974108
descriptionInteger types that are known not to equal any single N.
homepagehttps://github.com/Vonr/nonn
repositoryhttps://github.com/Vonr/nonn
max_upload_size
id956188
size51,967
Qther (Vonr)

documentation

README

nonn Crates.io

Integer types that are known not to equal any single N, enabling some memory layout optimization.

Most of nonn's code is lifted from core::num::nonzero and slightly adapted.

nonn is backed by core::num::NonZero*, ensuring

use std::mem::size_of;

assert_eq!(size_of::<Option<nonn::NonNU8<0>>>(), size_of::<u8>());
assert_eq!(size_of::<Option<nonn::NonNU16<1>>>(), size_of::<u16>());
assert_eq!(size_of::<Option<nonn::NonNU32<2>>>(), size_of::<u32>());
assert_eq!(size_of::<Option<nonn::NonNU64<3>>>(), size_of::<u64>());
assert_eq!(size_of::<Option<nonn::NonNU128<4>>>(), size_of::<u128>());
assert_eq!(size_of::<Option<nonn::NonNUsize<5>>>(), size_of::<usize>());
assert_eq!(size_of::<Option<nonn::NonNI8<6>>>(), size_of::<i8>());
assert_eq!(size_of::<Option<nonn::NonNI16<7>>>(), size_of::<i16>());
assert_eq!(size_of::<Option<nonn::NonNI32<8>>>(), size_of::<i32>());
assert_eq!(size_of::<Option<nonn::NonNI64<9>>>(), size_of::<i64>());
assert_eq!(size_of::<Option<nonn::NonNI128<10>>>(), size_of::<i128>());
assert_eq!(size_of::<Option<nonn::NonNIsize<11>>>(), size_of::<isize>());

nonn functions in no_std environments.

Limitations

NonN* types will inevitably introduce many branches in most methods. If you require higher performance, it is advisable to use either core::num::nonzero or the nonmax crate. These alternative options are more specialized and can thus avoid many of the checks nonn uses.

nonn currently does not implement Neg for its types, as Neg on NonNU*<N> should in theory result in NonNI*<-N>. This is currently not possible to my knowledge, even on nightly.

nonn requires at least Rust 1.57.0 to compile, but 1.67.0 or above is required for ilog2 and ilog10.

Commit count: 5

cargo fmt