Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vonr/nonn
Integer types that are known not to equal any single N.
https://github.com/vonr/nonn
Last synced: about 1 month ago
JSON representation
Integer types that are known not to equal any single N.
- Host: GitHub
- URL: https://github.com/vonr/nonn
- Owner: Vonr
- Created: 2023-08-27T16:17:54.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-08-29T10:46:26.000Z (over 1 year ago)
- Last Synced: 2024-11-12T19:14:59.849Z (about 2 months ago)
- Language: Rust
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nonn [![Crates.io](https://img.shields.io/crates/v/nonn)](https://crates.io/crates/nonn)
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](https://doc.rust-lang.org/src/core/num/nonzero.rs.html)
and slightly adapted.nonn is backed by `core::num::NonZero*`, ensuring
```rs
use std::mem::size_of;assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
assert_eq!(size_of::>>(), size_of::());
```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](https://doc.rust-lang.org/src/core/num/nonzero.rs.html) or
the [nonmax](https://docs.rs/nonmax/latest/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*` 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`.