Macro from_tuple

Source
macro_rules! from_tuple {
    ($name:ident { $($field:ident),* $(,)? }) => { ... };
}
Expand description

Generates a closure that constructs a struct from a tuple. The struct fields must be exactly in the order in which they’re expected to be in the tuple.

use shrimple_parser::{Parser, pattern::parse_until_ex, from_tuple};

#[derive(Debug, PartialEq, Eq)]
struct Example<'src> { a: &'src str, b: &'src str }

let input = "abc|def|";
let res = parse_until_ex::<_, ()>("|")
    .and(parse_until_ex("|"))
    .map_out(from_tuple!(Example { a, b }))
    .parse(input);
assert_eq!(res, Ok(("", Example { a: "abc", b: "def" })))