Macro shrimple_parser::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, parse_until_exact, from_tuple};

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

let input = "abc|def|";
let res = parse_until_exact("|")
    .and(parse_until_exact("|"))
    .map(from_tuple!(Example { a, b }))
    (input);
assert_eq!(res, Ok(("", Example { a: "abc", b: "def" })))