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.

Custom Derive Macros | Rust Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 49 of 50

·rust

Custom Derive Macros

12 minutes

Course progress98%

Custom Derive Macros

Create your own #[derive] macros to implement common functionality.

// In my_derive crate
#[proc_macro_derive(HelloWorld)]
pub fn hello_world_derive(input: TokenStream) -> TokenStream {
    // parse input and generate impl of a trait
    
    input
}
// simplified example

Then use it in another crate:

use my_derive::HelloWorld;

#[derive(HelloWorld)]
struct Foo;
Make it stickPractice what you've learned1 quiz · 1 practical test · Optional activities from Rust FundamentalsBrowse activities
Previous lessonProcedural Macros OverviewContinue to lesson 50Deploying Rust ApplicationsBack to Rust Fundamentals curriculum