BT

Rust 1.15 Brings Custom Derive

| by James Chesters Follow 1 Followers on Feb 05, 2017. Estimated reading time: 2 minutes |

The Rust core team has released the stable version of 1.15, bringing with it the highly anticipated custom derive, allowing code-generating crates like Serde and Diesel to work ergonomically.

In the notes to RFC 1681 the motivation for custom derive is explained:

Some large projects in the ecosystem today, such as serde and diesel, effectively require the nightly channel of the Rust compiler. Although most projects have an alternative to work on stable Rust, this tends to be far less ergonomic and comes with its own set of downsides, and empirically it has not been enough to push the nightly users to stable as well...

The good news, however, is that this class of projects which require nightly Rust almost all require nightly for the reason of procedural macros. Even better, the full functionality of procedural macros is rarely needed, only custom derive! Even better, custom derive typically doesn't require the features one would expect from a full-on macro system, such as hygiene and modularity, that normal procedural macros typically do.

A Diesel use case is provided in the blog post Announcing Rust 1.15:

// some extern crate and use lines elided here

#[derive(Queryable)]
struct Pet {
    name: String,
}

fn main() {
    use diesel_demo::schema::pets::dsl::*;

    let connection = establish_connection();
    let results = pets
        .limit(5)
        .load::<Pet>(&connection)
        .expect("Error loading pets");

    println!("Displaying {} pets", results.len());
    for pet in results {
        println!("{}", pet.name);
    }
}

Aside from custom derive, other improvements in Rust 1.15 include a re-written build system, using Cargo. The Rust team comments:

Given that all Rust development happens on the master branch, we’ve been using it since December of last year, and it’s working well. There is an open PR to remove the Makefiles entirely, landing in Rust 1.17. This will pave the way for rustc to use packages from crates.io in the compiler like any other Rust project.

In other areas of significance, with the 1.15 stable release Rust has gained Tier 3 support for i686-unknown-openbsd, MSP430, and ARMv5TE. In the Hacker News discussion around the release, user thenewwazoo commented "WHOA! MSP430 support is HUGE. In case you don't know, that's a well-known very low-power microcontroller... this might be the only current platform that's <32 bits. I know there was some work on supporting the 8-bit AVR architecture, but MSP430 gets rust a lot closer to super-low-power applications."

Other users were equally excited about the release. Dikaiosune said, "This is pretty major. In anticipation of this release, I was able to remove all nightly feature flags from a smallish web backend which makes heavy use of type-driven codegen (serde and diesel). Really, truly, utterly fantastic to have stability promises for custom_derive. So excited!"

Ekidd agreed, adding, "We have a bunch of Rust apps at work, and just one of them was still on nightly, and now we can move that to stable, too. And we can get rid of a bunch of build.rs scripts elsewhere, which is always nice."

Detailed release notes for Rust 1.15 are available on GitHub, and the release can be downloaded from here.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT