Search code examples
floating-pointrustnom

How to parse complete f32 with nom?


There is a function float_s that parses floats in stream mod (can return Incomplete). I want to use CompleteStr as input type instead. How I can achieve that?

Simple approach fails with complains about &str and CompleteStr mismatches:

named!(parse_float_complete(CompleteStr) -> f32,
    ws!(::num::float_s)
);

I'm using nom 4.0.0.


Solution

  • nom v4.1.0 fixed this problem:

    • float and double now work on all of nom's input types (&[u8], &str, CompleteByteSlice, CompleteStr and any type that implements the required traits). float_s and double_s got the same modification, but are now deprecated