Lesson 48 of 50 · rust
Procedural Macros Overview
Duration: 15 minutes
Lesson 48 of 50 · rust
Duration: 15 minutes
#[derive], attribute macros, and function‑like macros.\n\ntoml\n# Cargo.toml for the macro crate\n[lib]\nproc-macro = true\n\n\nrust\nextern crate proc_macro;\nuse proc_macro::TokenStream;\n\n#[proc_macro_derive(MyTrait)]\npub fn my_trait_derive(input: TokenStream) -> TokenStream {\n // generate impl here\n input\n}\n\n\nConsume the macro by adding the crate as a dependency.