[][src]Function lexical::parse_lossy

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

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

This function always returns a number, parsing until invalid digits are found. For an error-checking version of this function, use try_parse.

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

  • bytes - Byte slice to convert to number.

Examples

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

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