macro
The proc_macro compiler API
The compiler provides proc_macro for implementing macro entry points. The echo example returns the input unchanged; it does not evaluate the expression itself. Example: two-crate workspace; see fixtures/proc-macro-workspace/consumer/src/bin/proc_macro_api.rs. This caller is not a standalone rustc program. Expected stdout (not executed): '12\n' Common mistake: Importing proc_macro in an ordinary application and expecting its compiler-backed operations to work there.
Formal Syntax & Structure
rust syntaxrust
use proc_macro::TokenStream;Working Example
Example Snippetrust
use teaching_macros::echo_tokens;fn main() { println!("{}", echo_tokens!(4 * 3)); }