macro
Expansion versus runtime execution
Macro expansion supplies syntax before the resulting program executes. A mutable variable used in the echoed expression is read when the resulting program runs, not by the macro during compilation. Example: two-crate workspace; see fixtures/proc-macro-workspace/consumer/src/bin/expansion.rs. This caller is not a standalone rustc program. Expected stdout (not executed): '2\n5\n' Common mistake: Assuming a procedural macro can inspect the runtime value of a local variable.
Formal Syntax & Structure
rust syntaxrust
echo_tokens!(expression)Working Example
Example Snippetrust
use teaching_macros::echo_tokens;fn main() { let mut n = 2; println!("{}", echo_tokens!(n)); n += 3; println!("{}", echo_tokens!(n)); }