Function lexical::parse_partial_lossy[][src]

pub fn parse_partial_lossy<N: FromLexicalLossy, Bytes: AsRef<[u8]>>(
    bytes: Bytes
) -> Result<(N, usize)>

High-level, partial, lossy conversion of decimal-encoded bytes to a number.

This function uses aggressive optimizations to avoid worst-case scenarios, and can return inaccurate results. For guaranteed accurate floats, use parse_partial.

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.

  • bytes - Byte slice to convert to number.

Examples


// String overloads
assert_eq!(lexical::parse_partial_lossy::<f32, _>("0"), Ok((0.0, 1)));
assert_eq!(lexical::parse_partial_lossy::<f32, _>("1.0"), Ok((1.0, 3)));
assert_eq!(lexical::parse_partial_lossy::<f32, _>("1."), Ok((1.0, 2)));

// Bytes overloads
assert_eq!(lexical::parse_partial_lossy::<f32, _>(b"0"), Ok((0.0, 1)));
assert_eq!(lexical::parse_partial_lossy::<f32, _>(b"1.0"), Ok((1.0, 3)));
assert_eq!(lexical::parse_partial_lossy::<f32, _>(b"1."), Ok((1.0, 2)));