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
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Procedural Macros Overview | Rust Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 48 of 50

·rust

Procedural Macros Overview

15 minutes

Course progress96%

Procedural Macros Overview

Procedural macros let you generate Rust code at compile time. There are three kinds: #[derive], attribute macros, and function‑like macros.

# Cargo.toml for the macro crate
[lib]
proc-macro = true
extern crate proc_macro;
 proc_macro::TokenStream;


  (input: TokenStream)  TokenStream {
    
    input
}
use
#[proc_macro_derive(MyTrait)]
pub
fn
my_trait_derive
->
// generate impl here

Consume the macro by adding the crate as a dependency.

Make it stickPractice what you've learned1 quiz · 1 practical test · Optional activities from Rust FundamentalsBrowse activities
Previous lessonInterior Mutability with RefCellContinue to lesson 49Custom Derive MacrosBack to Rust Fundamentals curriculum