[][src]Macro squote::quote

macro_rules! quote {
    () => { ... };
    ($($tt:tt)*) => { ... };
}

The whole point.

Performs variable interpolation against the input and produces it as TokenStream.

Interpolation

Variable interpolation is done with #var (similar to $var in macro_rules! macros). This grabs the var variable that is currently in scope and inserts it in that location in the output tokens. Any type implementing the ToTokens trait can be interpolated. This includes most Rust primitive types.

Repetition is done using #(...)* or #(...),* again similar to macro_rules!. This iterates through the elements of any variable interpolated within the repetition and inserts a copy of the repetition body for each one. The variables in an interpolation may be a Vec, slice, BTreeSet, or any Iterator.

  • #(#var)* — no separators
  • #(#var),* — the character before the asterisk is used as a separator
  • #( struct #var; )* — the repetition can contain other tokens
  • #( #k => println!("{}", #v), )* — even multiple interpolations