Function lexical_core::parse_with_options
source · pub fn parse_with_options<N: FromLexicalWithOptions, const FORMAT: u128>(
bytes: &[u8],
options: &N::Options,
) -> Result<N>
Expand description
Parse complete number from string with custom parsing options.
This method parses the entire string, returning an error if any invalid digits are found during parsing.
FORMAT
- Packed struct containing the number format.bytes
- Byte slice containing a numeric string.options
- Options to customize number parsing.
§Example
#[cfg(all(feature = "parse-floats", feature = "format"))] {
const JSON: u128 = lexical_core::format::JSON;
let options = lexical_core::ParseFloatOptions::new();
let string = "3.14159265359";
let result = lexical_core::parse_with_options::<f32, JSON>(string.as_bytes(), &options);
assert_eq!(result, Ok(3.14159265359_f32));