Lesson 49 of 50 · rust
Custom Derive Macros
Duration: 12 minutes
Lesson 49 of 50 · rust
Duration: 12 minutes
#[derive] macros to implement common functionality.\n\nrust\n// In my_derive crate\n#[proc_macro_derive(HelloWorld)]\npub fn hello_world_derive(input: TokenStream) -> TokenStream {\n // parse input and generate impl of a trait\n // simplified example\n input\n}\n\n\nThen use it in another crate:\n\nrust\nuse my_derive::HelloWorld;\n\n#[derive(HelloWorld)]\nstruct Foo;\n\n