operator

Macro operator 

Source
macro_rules! operator {
    ($($(#[$attribute:meta])* $pub:vis $name:ident = $op:literal);*$(;)?) => { ... };
    (@operator $(#[$attribute:meta])* $pub:vis $name:ident = $op:literal) => { ... };
    (@char_at $at:literal $op:literal) => { ... };
}
Expand description

Define types matching operators (punctuation sequences).

operator!{ pub Op = "punct"; ...}

  • A optional pub defines the operators public, default is private
  • Op is the name for the struct to be generated
  • "punct" is up to 4 ASCII punctuation characters

Op::parse() will match the defined operator. It will implement Debug and Clone for operators.

The [unsynn!] macro supports defining operators by using operator Op = "chars";, the pub specification has to come before operator then. See the unsynn! operator documentation for details.

For predefined operators, see operator::names which includes common operators like Plus, Minus, Star, Arrow, etc.

ยงExample

operator!{
    /// Optional documentation for `<~~`
    WLArrow = "<~~";
    WRArrow = "~~>";
}

let mut tokens = "<~~~~> ~~><~~".to_token_iter();
let wl = WLArrow::parse(&mut tokens).unwrap();
assert_tokens_eq!(wl, str "<~~");
let wr = WRArrow::parse(&mut tokens).unwrap();
assert_tokens_eq!(wr, str "~~>");