Crate sign_bound

Crate sign_bound 

Source
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 NegativeI8 checked at compile time.
negative_i16
Creates a NegativeI16 checked at compile time.
negative_i32
Creates a NegativeI32 checked at compile time.
negative_i64
Creates a NegativeI64 checked at compile time.
negative_isize
Creates a NegativeIsize checked at compile time.
positive_i8
Creates a PositiveI8 checked at compile time.
positive_i16
Creates a PositiveI16 checked at compile time.
positive_i32
Creates a PositiveI32 checked at compile time.
positive_i64
Creates a PositiveI64 checked at compile time.
positive_isize
Creates a PositiveIsize checked at compile time.

Structs§

NegativeI8
A signed value that is known to be negative.
NegativeI16
A signed value that is known to be negative.
NegativeI32
A signed value that is known to be negative.
NegativeI64
A signed value that is known to be negative.
NegativeIsize
A signed value that is known to be negative.
PositiveI8
A signed value that is known to be positive.
PositiveI16
A signed value that is known to be positive.
PositiveI32
A signed value that is known to be positive.
PositiveI64
A signed value that is known to be positive.
PositiveIsize
A signed value that is known to be positive.