Skip to main content

decl_keyword

Macro decl_keyword 

Source
macro_rules! decl_keyword {
    { $(#[$meta:meta])* $v:vis
      $name:ident { $( $($anno:ident)? $($s:literal)|+ => $i:ident),* $(,)? } } => { ... };
    [ @impl is_anno annotation ] => { ... };
    [ @impl is_anno $x:ident ] => { ... };
    [ @impl is_anno ] => { ... };
    [ @impl join $s:literal ] => { ... };
    [ @impl join $s:literal , $($ss:literal),+ ] => { ... };
}
Expand description

Macro for declaring a keyword enumeration to help parse a document.

A keyword enumeration implements the Keyword trait.

These enums are a bit different from those made by caret, in a few ways. Notably, they are optimized for parsing, they are required to be compact, and they allow multiple strings to be mapped to a single index.

decl_keyword! {
   Location {
       "middle" | "center" => MID,
       "end" => END
   }
}

assert_eq!(Location::from_str("start"), Location::START);
assert_eq!(Location::from_str("stfff"), Location::UNRECOGNIZED);