sign-bound

Crates.iosign-bound
lib.rssign-bound
version
sourcesrc
created_at2024-09-21 00:11:19.552365
updated_at2024-12-02 21:14:42.730901
descriptionLayout-optimized positive and negative integers
homepagehttps://github.com/jf2048/sign-bound
repositoryhttps://github.com/jf2048/sign-bound.git
max_upload_size
id1381858
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Jason Francis (jf2048)

documentation

https://docs.rs/sign-bound

README

sign-bound   Latest Version Documentation

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, NegativeI8
  • PositiveI16, NegativeI16
  • PositiveI32, NegativeI32
  • PositiveI64, NegativeI64
  • PositiveIsize, NegativeIsize

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.

Commit count: 11

cargo fmt