#hexadecimal #hex #decimal #octal #binary

parse_int

Parse &str with common prefixes to integer values

8 releases (5 breaking)

0.6.0 Sep 6, 2021
0.5.0 Jan 9, 2021
0.4.0 Jan 14, 2020
0.3.0 Jan 13, 2020
0.1.1 Jan 6, 2020

#28 in Parser tooling

Download history 1195/week @ 2021-06-06 1290/week @ 2021-06-13 1119/week @ 2021-06-20 1183/week @ 2021-06-27 1297/week @ 2021-07-04 1217/week @ 2021-07-11 1437/week @ 2021-07-18 1725/week @ 2021-07-25 1420/week @ 2021-08-01 1539/week @ 2021-08-08 1755/week @ 2021-08-15 1628/week @ 2021-08-22 1449/week @ 2021-08-29 1729/week @ 2021-09-05 1793/week @ 2021-09-12 1480/week @ 2021-09-19

5,977 downloads per month
Used in 12 crates (11 directly)

Apache-2.0/MIT/BSL-1.0/CC0-1.0

12KB
205 lines

parse_int

crates.io CI pipeline

Parse &str with common prefixes to integer values:

use parse_int::parse;

let d = parse::<usize>("42")?;
assert_eq!(42, d);

let d = parse::<isize>("0x42")?;
assert_eq!(66, d);

// you can use underscores for more readable inputs
let d = parse::<isize>("0x42_424_242")?;
assert_eq!(1_111_638_594, d);

let d = parse::<u8>("0o42")?;
assert_eq!(34, d);
#[cfg(feature = "implicit-octal")]
{
    let d = parse::<u8>("042")?;
    assert_eq!(34, d);
}

let d = parse::<u16>("0b0110")?;
assert_eq!(6, d);

Documentation.

Enable the "implicit-octal" feature

Specify the crate like this:

[dependencies]
parse_int = { version = "0.5", features = ["implicit-octal"] }

Then this code will return Hello, Ok(34)!:

use parse_int::parse;
fn main() {
    println!("Hello, {:?}!", parse::<i128>("00042"));
}

License

This work is distributed under the super-Rust quad-license:

Apache-2.0/MIT/BSL-1.0/CC0-1.0

This is equivalent to public domain in jurisdictions that allow it (CC0-1.0). Otherwise it is compatible with the Rust license, plus the option of the runtime-exception-containing BSL-1. This means that, outside of public domain jurisdictions, the source must be distributed along with author attribution and at least one of the licenses; but in binary form no attribution or license distribution is required.

Dependencies

~140KB