Function lexical_core::parse_partial_with_options
source · [−]pub fn parse_partial_with_options<N: FromLexicalWithOptions, const FORMAT: u128>(
bytes: &[u8],
options: &N::Options
) -> Result<(N, usize)>
Expand description
Parse partial number from string with custom parsing options.
This method parses until an invalid digit is found (or the end of the string), returning the number of processed digits and the parsed value until that point.
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 hello";
let result = lexical_core::parse_partial_with_options::<f32, JSON>(string.as_bytes(), &options);
assert_eq!(result, Ok((3.14159265359_f32, 13)));