6 releases

0.1.6 Oct 30, 2020
0.1.5 Oct 30, 2020
0.1.4 Apr 3, 2019
0.1.2 Dec 18, 2018

#415 in Algorithms

Download history 1369/week @ 2023-01-31 1579/week @ 2023-02-07 1859/week @ 2023-02-14 2111/week @ 2023-02-21 2107/week @ 2023-02-28 1618/week @ 2023-03-07 1515/week @ 2023-03-14 1421/week @ 2023-03-21 1000/week @ 2023-03-28 1186/week @ 2023-04-04 1324/week @ 2023-04-11 1485/week @ 2023-04-18 1318/week @ 2023-04-25 1085/week @ 2023-05-02 1425/week @ 2023-05-09 1849/week @ 2023-05-16

6,116 downloads per month
Used in 71 crates (5 directly)

Apache-2.0 OR MIT

8KB
66 lines

A series of fixed non-negative integer types.

Constructors

This crate provides a series of macros that used to construct fixed uints in compile time.

The input is a string literal, and the macros support several formats of the input:

  • A decimal string.
  • A binary string with 0b prefix.
  • A octal string with 0o prefix.
  • A hexadecimal string with 0x prefix.

And you can use any number of _ in the string literal to separate it for more readable.

Examples

use numext_fixed_uint::{u128, U128};

const U128_100: U128 = u128!("100");

fn main () -> ::std::io::Result<()> {
    let x1 = u128!("0b110_0100");
    let x2 = u128!("0o144");
    let x3 = u128!("0x64");
    let y = U128::from(100u8);
    assert_eq!(x1, y);
    assert_eq!(x2, y);
    assert_eq!(x3, y);
    assert_eq!(U128_100, y);
    Ok(())
}

Dependencies

~0.5–1MB
~23K SLoC