O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Aster

There's a library that abstracts some of the details of macro building called AST builder (aster). It's part of the serialization project, serde, and can be found at https://github.com/serde-rs/aster. Let's take a look at how to build extensions with it. To make it a tad more interesting, we'll write the code in such a way that both unstable and stable compilers are supported via configuration attributes.

This example will again be in a full Cargo project, since including and configuring an external crate is much easier this way. Plus, we can set up conditional compilation based on stable Rust this way. The project tree will be quite regular, with just the minimal required Cargo.toml and src/main.rs.

Here's how to set up Cargo.toml ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required