Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Use .map With tuple() In The nom Parser In Rust

This returns a [TODO: Code shorthand span ] instead of a [TODO: Code shorthand span ]

rust
use nom::bytes::complete::tag;
use nom::character::complete::multispace1;
use nom::sequence::tuple;
use nom::IResult;

fn main() {
    let (a, b) = parse("alfa bravo charlie").unwrap();
    dbg!(a);
    dbg!(b);
}

fn parse(source: &str) -> IResult<&str, &str> {
    let (a, b) = tuple((
        tag("alfa"), 
        multispace1, 
        tag("bravo"))
    )(source)
        .map(|(x, y)| (x, y.2))?;
    Ok((a, b))
}

Footnotes And References