[−][src]Macro combine::struct_parser
Sequences multiple parsers and builds a struct out of them.
#[macro_use] extern crate combine; use combine::{Parser, many, token}; use combine::byte::{letter, spaces}; #[derive(Debug, PartialEq)] struct Field { name: Vec<u8>, value: Vec<u8>, } fn main() { let mut parser = struct_parser!{ Field { name: many(letter()), // `_` fields are ignored when building the struct _: spaces(), _: token(b':'), _: spaces(), value: many(letter()), } }; assert_eq!( parser.parse(&b"test: data"[..]), Ok((Field { name: b"test"[..].to_owned(), value: b"data"[..].to_owned() }, &b""[..])) ); }