macro_rules! construct {
($struct:ident { $( $field:ident ),* $(,)? }) => { ... };
($enum:ident :: $constr:ident { $( $field:ident ),* $(,)? }) => { ... };
($struct:ident ( $( $field:ident ),* $(,)? )) => { ... };
($enum:ident :: $constr:ident ( $( $field:ident ),* $(,)? )) => { ... };
($($x:ident),* $(,)?) => { ... };
}
Expand description
Compose several parsers to produce a single result
Every parser must succeed in order to produce a result
Each parser must be present in a local scope and have the same name as struct field.
struct Res {
a: bool,
b: u32,
}
let a: Parser<bool> = short('a').switch();
let b: Parser<u32> = short('b').argument("B").from_str();
let res: Parser<Res> = construct!(Res { a, b });
construct!
supports following representations:
- structs with unnamed fields:
ⓘ
construct!(Res(a, b))
- structs with named fields:
ⓘ
construct!(Res {a, b})
- enums with unnamed fields:
ⓘ
construct!(Ty::Res(a, b))
- enums with named fields:
ⓘ
construct!(Ty::Res {a, b})
- tuples:
ⓘ
construct!(a, b)