Function lexical::parse_partial_with_options
source · pub fn parse_partial_with_options<N: FromLexicalWithOptions, Bytes: AsRef<[u8]>, const FORMAT: u128>(
bytes: Bytes,
options: &N::Options,
) -> Result<(N, usize)>
Expand description
High-level, partial conversion of bytes to a number with custom parsing options.
This functions parses as many digits as possible, returning the parsed value and the number of digits processed if at least one character is processed. If another error, such as numerical overflow or underflow occurs, this function returns the error code and the index at which the error occurred.
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_partial_with_options::<f32, _, FORMAT>("0", &options), Ok((0.0, 1)));
assert_eq!(lexical::parse_partial_with_options::<f32, _, FORMAT>("1,2345", &options), Ok((1.2345, 6)));
assert_eq!(lexical::parse_partial_with_options::<f32, _, FORMAT>("1,2345^4", &options), Ok((12345.0, 8)));