macro_rules! parser_byte_map {
(
$($($l:literal)|+ => $e:expr),+$(,)?
) => { ... };
}
Expand description
Macro to define a parser which consumes a single byte and maps it using a lookup table.
This macro is a wrapper around parser::byte_lut
to allow defining
the lookup table using a match-like syntax. Each expression must be const and evaluate to a
value of the same copy type.
ยงExamples
let parser = parser::byte_map!(
b'#' => true,
b'.' | b'S' => false,
);
assert_eq!(parser.parse(b"#.S##"), Ok((true, &b".S##"[..])));
assert_eq!(parser.parse(b".S##"), Ok((false, &b"S##"[..])));
assert_eq!(parser.parse(b"S##"), Ok((false, &b"##"[..])));
let (err, remaining) = parser.parse(b"abc").unwrap_err();
assert_eq!(err.to_string(), "expected one of '#', '.', 'S'");
assert_eq!(remaining, &b"abc"[..]);