Loading tutorials
#[derive(Debug)]. You don't need to have written a macro before. Later chapters build the tools in det6 min read#[derive(Debug)] and similar attributes. You do not need to know macro_rules!. By the end you will have a working proc-macro crate, you will know which rules rustc enforces on it, and you will kno4 min readproc-macro = true under [lib]. You don't need syn or quote yet. Everything here uses only the compiler's own proc_macro library, so the crate has no dependencies.5 min readsyn turns the raw tokens a procedural macro receives into typed Rust values you can inspect. It assumes you can read Rust traits and generics, know how a proc-macro crate is set up (proc-macro = true in [lib]), and know that a macro function takes a TokenStream and ret4 min readDeriveInput out of syn. The quote crate covers the other half of the job: turning values you have already parsed back into4 min readTokenStream, and on syn and quote. You should be comfortable with Rust traits, Result, and Cargo dependencies. If macro_rules! is familiar, that helps, but it is not required.5 min read#[derive(Name)] on a struct, enum, or union. It reads the definition of that type and returns extra items, usually an impl block. This chapter builds one end to end and covers the points that commonly go wrong.4 min readsyn and quote, and that you know Rust generics, trait bounds, and where clauses. By the end you will be able to make a derive macro work for types such as Wrapper<T>, Ref<'a, T>, and Buf<const N: usize>.4 min readTokenStream5 min readsyn and quote, and that you know Result and the ? operator. By the end you will turn bad macro input into normal compiler errors that point at the right line of the user's code.5 min readsyn and quote, as in the earlier chapters. You should also know how a DeriveInput represents a struct and its fields. The examples use syn 2 with the full feature, in a proc-macro crate named my_macros.4 min readproc-macro = true in Cargo.toml, TokenStream in and out, and the syn and quote basics from the earlier chapters. You should also be comfortable with ItemFn, DeriveInput and syn::Error.4 min readsyn and quote, including error reporting with syn::Error. It also assumes you know Cargo workspaces and dev-dependencies. Macros are hard to debug because the code you wrote is not the code the compiler checks. The compiler checks 5 min readsyn and quote, that you know what a TokenStream is, and that you hav6 min read