Common Macro Patterns and Best Practices in Rust

Use declarative macros for repetition and procedural macros for custom derives to generate code at compile time.

Use declarative macros with macro_rules! for code repetition and procedural macros with #[derive] or #[proc_macro] for custom attributes and derives. Declarative macros expand at compile time using pattern matching, while procedural macros are Rust functions that generate code.

macro_rules! say_hello {
    () => {
        println!("Hello!");
    };
}

say_hello!();