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 ...
}