Function konst::primitive::parse_i128
source · pub const fn parse_i128(s: &str) -> Result<i128, ParseIntError>
Expand description
Parses a i128
from a &str
.
This returns an Err
if the string would not successfully .parse()
into a i128
.
To parse a i128
from only part of a string, you can use Parser::parse_i128
.
§Example
use konst::{
primitive::{ParseIntResult, parse_i128},
unwrap_ctx,
};
const I: ParseIntResult<i128> = parse_i128("1234");
assert_eq!(I, Ok(1234));
assert_eq!(parse_i128("123"), Ok(123));
assert_eq!(parse_i128("0"), Ok(0));
assert_eq!(parse_i128("-1"), Ok(-1));
// This is how you can unwrap integers parsed from strings, at compile-time.
const I2: i128 = unwrap_ctx!(parse_i128("1234"));
assert_eq!(I2, 1234);
assert!(parse_i128("100A").is_err());
assert!(parse_i128("-A").is_err());
assert!(parse_i128("-").is_err());