Module quote
Quasi-quoting for generating Rust source code as tokens.
quote provides the quote! macro,
which turns Rust syntax into a proc_macro2::TokenStream.
It is one of the three foundational crates for writing procedural macros,
alongside syn for parsing and proc_macro2 for token representation.
The quote! macro supports interpolation of variables with #var
and repetition with #( ... )*, mirroring the patterns of macro_rules!.
Example
Generating a token stream with interpolation:
use quote;
use Ident;
let name = new;
let field_name = new;
let tokens = quote! ;
let code = tokens.to_string;
assert!;
assert!;
Macros
-
format_ident
Formatting macro for constructing
Idents. - quote The whole point.
-
quote_spanned
Same as
quote!, but applies a given span to all tokens originating within the macro invocation.