Expand description
§sign-bound
Signed integer types for Rust that are bounded to be either positive or negative. The API is
analogous to the built-in NonZero types. The 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.
Macros§
- negative_
i8 - Creates a
NegativeI8checked at compile time. - negative_
i16 - Creates a
NegativeI16checked at compile time. - negative_
i32 - Creates a
NegativeI32checked at compile time. - negative_
i64 - Creates a
NegativeI64checked at compile time. - negative_
isize - Creates a
NegativeIsizechecked at compile time. - positive_
i8 - Creates a
PositiveI8checked at compile time. - positive_
i16 - Creates a
PositiveI16checked at compile time. - positive_
i32 - Creates a
PositiveI32checked at compile time. - positive_
i64 - Creates a
PositiveI64checked at compile time. - positive_
isize - Creates a
PositiveIsizechecked at compile time.
Structs§
- Negative
I8 - A signed value that is known to be negative.
- Negative
I16 - A signed value that is known to be negative.
- Negative
I32 - A signed value that is known to be negative.
- Negative
I64 - A signed value that is known to be negative.
- Negative
Isize - A signed value that is known to be negative.
- Positive
I8 - A signed value that is known to be positive.
- Positive
I16 - A signed value that is known to be positive.
- Positive
I32 - A signed value that is known to be positive.
- Positive
I64 - A signed value that is known to be positive.
- Positive
Isize - A signed value that is known to be positive.