pub fn float<T, E>(input: T) -> Result<(T, f32), Err<E>>where
E: ParseError<T>,
T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Slice<Range<usize>> + Clone + Offset + ParseTo<f32> + Compare<&'static str> + InputIter + InputLength + InputTake + InputTakeAtPosition + AsBytes + for<'a> Compare<&'a [u8]>,
<T as InputIter>::Item: AsChar + Copy,
<T as InputIter>::IterElem: Clone,
<T as InputTakeAtPosition>::Item: AsChar,
Available on crate feature
mtls
only.Expand description
Recognizes floating point number in text format and returns a f32.
Complete version: Can parse until the end of input.
use nom::number::complete::float;
let parser = |s| {
float(s)
};
assert_eq!(parser("11e-1"), Ok(("", 1.1)));
assert_eq!(parser("123E-02"), Ok(("", 1.23)));
assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Float))));