nom
nom copied to clipboard
Documentation example giving error
I'm doing the example from the docs here: https://docs.rs/nom/latest/nom/combinator/fn.map_res.html
let mut parse = map_res(digit1, |s: &str| s.parse::<u8>());
That gives:
error[E0283]: type annotations needed
--> src/main.rs:31:24
|
31 | let base = map_res(digit1, |s: &str| s.parse::<u32>());
| ------- ^^^^^^ cannot infer type of the type parameter `E` declared on the function `digit1`
| |
| type must be known at this point
|
= note: cannot satisfy `_: FromExternalError<&str, ParseIntError>`
note: required by a bound in `map_res`
No idea why the example from the documentation would be failing here.
This does work:
let (base, e): (&str, u32) = map_res(digit1, str::parse)(input)?;
So there's a big gap between calling the parser and assigning it to a local variable.