What is the difference between macro_rules and proc_macro

macro_rules! uses pattern matching for simple code generation, while proc_macro uses functions to manipulate the AST for complex derives and attributes.

The macro_rules! macro is a declarative, pattern-matching tool for general metaprogramming, while proc_macro is a procedural, function-based system for custom derives, attributes, and function-like macros that manipulate the AST.

// Declarative: Pattern matching on tokens
macro_rules! vec {
    ( $( $x:expr ),* ) => { /* ... */ };
}

// Procedural: Function receiving TokenStream
use proc_macro::TokenStream;
#[proc_macro_derive(HelloMacro)]
pub fn hello_macro_derive(input: TokenStream) -> TokenStream {
    // ... AST manipulation ...
}