Function lexical::parse_with_options
source · [−]pub fn parse_with_options<N: FromLexicalWithOptions, Bytes: AsRef<[u8]>, const FORMAT: u128>(
bytes: Bytes,
options: &N::Options
) -> Result<N>
Expand description
High-level conversion of bytes to a number with custom parsing options.
This function only returns a value if the entire string is successfully parsed.
FORMAT
- Packed struct containing the number format.bytes
- Byte slice to convert to number.options
- Options to specify number parsing.
Panics
If the provided FORMAT
is not valid, the function may panic. Please
ensure is_valid()
is called prior to using the format, or checking
its validity using a static assertion.
Examples
const FORMAT: u128 = lexical::format::STANDARD;
let options = lexical::ParseFloatOptions::builder()
.exponent(b'^')
.decimal_point(b',')
.build()
.unwrap();
assert_eq!(lexical::parse_with_options::<f32, _, FORMAT>("0", &options), Ok(0.0));
assert_eq!(lexical::parse_with_options::<f32, _, FORMAT>("1,2345", &options), Ok(1.2345));
assert_eq!(lexical::parse_with_options::<f32, _, FORMAT>("1,2345^4", &options), Ok(12345.0));