Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation example giving error #1590

Open
alper opened this issue Dec 13, 2022 · 1 comment
Open

Documentation example giving error #1590

alper opened this issue Dec 13, 2022 · 1 comment

Comments

@alper
Copy link

alper commented Dec 13, 2022

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.

@alper
Copy link
Author

alper commented Dec 13, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant