Any good resources for learning Rust macros?

This page summarizes the projects mentioned and recommended in the original post on /r/rust

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • rsx

    Advanced JSX-like templating for Rust

  • For me the real cool stuff is made possible through proc macros. They take as input a stream of tokens and output a stream of tokens. For example you can use these to make embedded DSLs in rust (example JSX in rust).

  • syn

    Parser for Rust source code

  • Or you can pair them with crates like syn, and quote for quasi-quoting, and then it's easy to make transformations on the AST of Rust input code. A lot of libraries do this for code-generation and hiding away a lot of complexity (example wasm-bindgen).

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • quote

    Rust quasi-quoting

  • Or you can pair them with crates like syn, and quote for quasi-quoting, and then it's easy to make transformations on the AST of Rust input code. A lot of libraries do this for code-generation and hiding away a lot of complexity (example wasm-bindgen).

  • wasm-bindgen

    Facilitating high-level interactions between Wasm modules and JavaScript

  • Or you can pair them with crates like syn, and quote for quasi-quoting, and then it's easy to make transformations on the AST of Rust input code. A lot of libraries do this for code-generation and hiding away a lot of complexity (example wasm-bindgen).

  • cargo-expand

    Subcommand to show result of macro expansion

  • I recommend you play around with some libraries that use proc macros and then use cargo-expand (vscode + rust-analyzer has a feature like this too) to see the generated code from the macro. For example, try looking at the result of expanding wasm-bindgen's basic example code

  • proc-macro-workshop

    Learn to write Rust procedural macros  [Rust Latam conference, Montevideo Uruguay, March 2019]

  • David Tolnay’s procedural Rust workshop: https://github.com/dtolnay/proc-macro-workshop

  • case-studies

    Analysis of various tricky Rust code

  • Also I suggest his case studies repo since you are looking at what is possible: https://github.com/dtolnay/case-studies

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts