Series: The Rust Annals
Vol. I Issue 16 nlopes.dev
Announcing Rust 1.15
Custom derive moved one of Rust’s most widely used nightly-only capabilities onto stable Rust.
Rust 1.15’s leading change is custom derive, bringing widely used compile-time code generation for libraries such as Serde and Diesel to stable Rust. The release also makes the Rust-written, Cargo-based compiler build system the default, broadens target support, improves compiler and standard-library performance, and begins two Cargo compatibility transitions.
Custom derive brings library-defined derives to stable Rust
The derive attribute could previously implement only traits provided by the standard library. Rust 1.15 stabilizes custom derive, allowing libraries to supply their own derives and substantially reducing the boilerplate required to use libraries such as Serde and Diesel. These libraries already worked on stable Rust, but their custom derives had been among the most widely used nightly-only features.
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[derive(Serialize, Deserialize, Debug)]
struct Pet {
name: String,
}
fn main() {
let pet = Pet { name: String::from("Ferris") };
let serialized = serde_json::to_string(&pet).unwrap();
println!("serialized = {}", serialized);
let deserialized: Pet = serde_json::from_str(&serialized).unwrap();
println!("deserialized = {:?}", deserialized);
}serialized = {"name":"Ferris"}
deserialized = Pet { name: "Ferris" }The feature was specified by RFC 1681 and was also known as “macros 1.1.” It includes infrastructure intended to support further compile-time capabilities nicknamed “macros 2.0.” Authors can consult the procedural-macros chapter of The Rust Programming Language for instructions on writing custom derives.
A smaller language improvement permits ?Sized in where clauses. The second form below is now accepted and is equivalent to the first:
struct Foo<T: ?Sized> {
f: T,
}
struct Foo<T> where T: ?Sized {
f: T,
}
The Rust-written build system becomes the default and more targets gain support
The compiler’s build system has been rewritten in Rust using Cargo and is now the default. Rust development on the master branch had used it since December 2016. Removing the Makefiles remained planned for Rust 1.17; that follow-up was expected to pave the way for rustc to use packages from crates.io like other Rust projects.
Tier 3 support was added for i686-unknown-openbsd, MSP430, and ARMv5TE. The release also includes a number of compiler performance improvements.
Sorting, iteration, formatting, and collection operations get faster or more capable
slice::sort was rewritten from a straightforward merge sort into a hybrid merge sort influenced by Timsort, making it much faster. Extending a Vec<T> where T: Copy is also much faster, as are chars().count(), chars().last(), and char_indices().last(). Chinese characters now display correctly in fmt::Debug.
The following standard-library APIs are newly stable:
std::iter::Iterator::min_bystd::iter::Iterator::max_bystd::os::*::fs::FileExtstd::sync::atomic::Atomic*::get_mutstd::sync::atomic::Atomic*::into_innerstd::vec::IntoIter::as_slicestd::vec::IntoIter::as_mut_slicestd::sync::mpsc::Receiver::try_iterstd::os::unix::process::CommandExt::before_execstd::rc::Rc::strong_countstd::rc::Rc::weak_countstd::sync::Arc::strong_countstd::sync::Arc::weak_countstd::char::encode_utf8std::char::encode_utf16std::cell::Ref::clonestd::io::Take::into_inner
Cargo prepares automatic build-script discovery and corrects cross-compilation behavior
Cargo now warns when a package has a top-level file named build.rs without a build = "build.rs" annotation. Build scripts previously always required configuration; the warning preserves compatibility ahead of a future change that will infer a top-level build.rs as the build script.
Cargo build scripts no longer receive OUT_DIR at their own build time through env!("OUT_DIR"). Setting that value then was a bug and produced an incorrect value when cross-compiling; build scripts should inspect it at runtime with std::env.
cargo test now accepts --all, which is useful for workspaces. Cargo is now compiled statically against the MSVC CRT on Windows and links OpenSSL statically on Mac OS X.