macro
Mixed-site macro hygiene
A local binding introduced by a macro is distinct from a similarly named binding supplied by the caller. Pass caller values through captures rather than relying on accidental name resolution. Expected stdout (not executed): '12 10\n' Common mistake: Assuming the local fee in the expansion overwrites the caller’s fee.
Formal Syntax & Structure
rust syntaxrust
macro_rules! name { ... }Working Example
Example Snippetrust
macro_rules! add_fee { ($amount:expr) => {{ let fee = 2; $amount + fee }}; }fn main() { let fee = 10; println!("{} {fee}", add_fee!(fee)); }