| Crates.io | sign-bound |
| lib.rs | sign-bound |
| version | 2.2.0 |
| created_at | 2024-09-21 00:11:19.552365+00 |
| updated_at | 2024-12-21 22:28:48.383183+00 |
| description | Layout-optimized positive and negative integers |
| homepage | https://github.com/jf2048/sign-bound |
| repository | https://github.com/jf2048/sign-bound.git |
| max_upload_size | |
| id | 1381858 |
| size | 64,785 |
Signed integer types for Rust that are bounded to be either positive or
negative. The API is analogous to the built-in NonZero types:
PositiveI8, NegativeI8PositiveI16, NegativeI16PositiveI32, NegativeI32PositiveI64, NegativeI64PositiveIsize, NegativeIsizeThe types are all memory-layout optimized, so for example Option<PositiveI32>
and Option<NegativeI32> are both the same size as i32. Using additional
variants in an enum can also have some space benefits.
enum MyEnum {
A(PositiveI16),
B,
C,
D,
}
assert_eq!(size_of::<MyEnum>(), size_of::<PositiveI16>());
Note that due to the implementation details of this crate, the space optimization for any type will not occur if there are more than 128 additional enum variants.
Option<PositiveIsize> is particularly useful as a space-efficient optional
Vec index, since Rust's Vec structure is
limited to
isize::MAX entries.