Skip to content

Help with annotating space1 in tuple parser #400

Answered by epage
mzagrabe asked this question in Q&A
Discussion options

You must be logged in to vote

PResult is a type alias for Result with a default parameter for E so when you declare parse_digits, you are specifying an E implicitly. Since the tuple has to all have the same E, this lets Rust infer E for the other parsers which are generic.

What to do depends on what kind of error reporting you want. If you want the same error type as above, you could do

use winnow::Parser;
use winnow::ascii::space1;

fn main() {
    let mut input = "Game 10: foo";
    let foo = (
        "Game",
        space1::<_, winnow::error::ContextError>,
    ).parse_next(&mut input).unwrap();

    println!("{foo:?}");
}

Tips

  • Putting your top-level parser in a function provides an easier / cleaner way of specif…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mzagrabe
Comment options

Answer selected by mzagrabe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants