utility_macros_internals/
expect_token.rs1macro_rules! expect_token {
2 ($tokens:ident, ident) => {
3 match $tokens.next() {
4 Some(TokenTree::Ident(ident)) => ident,
5 _ => panic!("expected identifier"),
6 }
7 };
8 ($tokens:ident, ident = $expected:literal) => {
9 match $tokens.next() {
10 Some(TokenTree::Ident(ident)) if ident.to_string() == $expected => ident,
11 _ => panic!("expected `{}`", $expected),
12 }
13 };
14 ($tokens:ident, punct) => {
15 match $tokens.next() {
16 Some(TokenTree::Punct(punct)) => punct,
17 _ => panic!("expected punctuation"),
18 }
19 };
20 ($tokens:ident, punct = $expected:literal) => {
21 match $tokens.next() {
22 Some(TokenTree::Punct(punct)) if punct.as_char() == $expected => {}
23 _ => panic!("expected `{}`", $expected),
24 }
25 };
26}
27
28pub(crate) use expect_token;