Skip to content
/ exint Public

A no_std Rust library providing stack-allocated generic integers

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

l1h3r/exint

Repository files navigation

Exint - Exotic Integer Types

github crates.io docs.rs build status

A no_std Rust library providing stack-allocated generic integers.

Features

  • Generic integer types
    • Signed integers via int<N>
    • Unsigned integers via uint<N>
    • Small type aliases (eg. u24, u40, u80)
  • Usable in no-std environments
  • Usable in const contexts
  • Zero dependencies

Basic example

use exint::primitive::u24;

fn main() {
  let one: u24 = u24::from(1_u8);
  let two: u24 = u24::from(2_u8);

  assert_eq!(u24::MIN, u24::MAX.wrapping_add(one));
  assert_eq!(u24::MAX, u24::try_from(16777215_u32).unwrap());
  assert_eq!(u24::MAX / two, u24::MAX >> 1_u32);
}

Literals

exint provides a simple procedural macro to simplify working with literal values.

The above example can be re-written as:

use exint::primitive::u24;

fn main() {
  exint::uint! {
    assert_eq!(u24::MIN, u24::MAX.wrapping_add(1_u24));
    assert_eq!(u24::MAX, 16777215_u24);
    assert_eq!(u24::MAX / 2_u24, u24::MAX >> 1_u32);
  }
}

Use the exint::uint_strict! macro to avoid converting the core integer types.

use exint::uint;

fn main() {
  exint::uint! {
    let a: uint<3> = 123_u24;  // <-- Converted
    let b: uint<4> = 456_u32;  // <-- Converted
  }

  exint::uint_strict! {
    let a: uint<3> = 123_u24;  // <-- Converted
    let b: u32 = 456_u32;  // <-- Not converted
  }
}

Security

This crate is not intended for cryptographic use. Consider using crypto-bigint if you need an integer type suitable for cryptographic applications.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

A no_std Rust library providing stack-allocated generic integers

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages