Loading tutorials
macro_rules! and a #[derive(...)] attribute. You will set up the crate that holds procedural macros and check that it works from another crate.2 min readproc-macro = true and know what a #[proc_macro] function is. It does not use syn or quote yet. Those build on the types described here.2 min readTokenStream. Here you will turn that raw token stream into typed Rust values using the syn crate.2 min readsyn, quote, and proc-macro2 in its dependencies, and that you can parse a DeriveInput. It covers the output half of a macro: turning values into Rust code.2 min readsyn, quote, and proc-macro2. If not, review the chapters on crate setup and on syn and quote first.3 min readTokenStream is, and have used syn and quote at a basic level.2 min readsyn and quote, and that you know Rust generics, lifetimes, and where clauses. You will fix a derive macro that breaks on generic types.2 min readsyn and quote. You should also know what a TokenStream is. Here you learn what a span is, how spans decide which names resolve to what, and how to use them to place compiler errors.2 min readsyn and quote, and that you know what a TokenStream is. You will learn how to turn mistakes in a macro's input into compiler errors that point at the right place.2 min readsyn and quote, and that you know how syn::Error reports problems. Here you will let users configure a derive with their own attributes, such as #[describe(name = "...")].2 min readproc-macro = true, with syn, quote and proc-macro2). It also assumes you have written a derive macro and can use parse_macro_input! and quote!.2 min readsyn::Error to report problems, as in the earlier chapters. You should also be comfortable with cargo test and with dev-dependencies. Here you will test that your macro accepts valid input and rejects invalid input with a useful messag3 min readsyn, generate code with quote, and report errors with syn::Error. Here we cover what procedural macros cannot do, what they cost, and how to keep them maintainable.3 min read