Function extprim::traits::parse_rust_int_lit [] [src]

pub fn parse_rust_int_lit<T: Num>(s: &str, is_negative: bool) -> Result<T, T::FromStrRadixErr>

Parses a Rust integer literal into an actual integral type.

If is_negative is true, a negative sign will be added to the string before the conversion.

Examples

use extprim::traits::parse_rust_int_lit;
use extprim::u128::u128;
use extprim::i128::i128;

assert_eq!(parse_rust_int_lit::<u128>("100_000", false).unwrap(), u128::new(100_000));
assert_eq!(parse_rust_int_lit::<u128>("0xffffffff_ffffffff_22222222_22222222", false).unwrap(),
            u128::from_parts(0xffffffff_ffffffff, 0x22222222_22222222));
assert_eq!(parse_rust_int_lit::<i128>("0b111", true).unwrap(), i128::new(-0b111));
assert_eq!(parse_rust_int_lit::<i128>("0x80000000_00000000_00000000_00000000", true).unwrap(),
            i128::min_value());