The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

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

TODO: Pull subtitle into page object
Code
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))
}



Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

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

This returns a `&str`` instead of a `tuple``

-- code
-- 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))
}





-- ref
-- url: https://docs.rs/nom/latest/nom/sequence/fn.tuple.html
-- title: nom::sequence::tuple documentation

-- categories
-- Rust 
-- nom

-- metadata
-- date: 2023-06-22 14:42:01
-- id: 2rzyy9y1
-- site: aws
-- type: post
-- status: draft