Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 48 of 50 · rust

Procedural Macros Overview

Duration: 15 minutes

Procedural Macros Overview\n\nProcedural macros let you generate Rust code at compile time. There are three kinds: #[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.

Previous: Interior Mutability with RefCellNext: Custom Derive Macros