Series: The Rust Annals

Vol. I Issue 26 nlopes.dev

Announcing Rust 1.25

Stabilization of std::ptr::NonNull<T> enables niche optimization for safer unsafe code, libcore gains const Duration, and Cargo defaults to binary generation, significantly improving ergonomics.

Library stabilizations

The biggest story in libraries this release is std::ptr::NonNull<T>. This type is similar to *mut T, but is non-null and covariant. This blog post isn’t the right place to explain variance, but in a nutshell, NonNull<T>, well, guarantees that it won’t be null, which means that Option<NonNull<T>> has the same size as *mut T. If you’re building a data structure with unsafe code, NonNull<T> is often the right type for you!

libcore has gained a time module, containing the Duration type previously only available in libstd.

Additionally, the from_secs, and from_millis functions associated with Duration were made const fns, allowing them to be used to create a Duration as a constant expression.

See the detailed release notes for more.

Cargo features

Cargo’s CLI has one really important change this release: cargo new will now default to generating a binary, rather than a library. We try to keep Cargo’s CLI quite stable, but this change is important, and is unlikely to cause breakage.

For some background, cargo new accepts two flags: --lib, for creating libraries, and --bin, for creating binaries, or executables. If you don’t pass one of these flags, in previous versions of Cargo, it would default to --lib. We made this decision because each binary (often) depends on many libraries, and so the library case is more common. However, this is incorrect; each library is depended upon by many binaries. Furthermore, when getting started, what you often want is a program you can run and play around with. It’s not just new Rustaceans though; even very long-time community members have said that they find this default surprising. As such, we’re changing it.

Similarly, cargo new previously would be a bit opinionated around the names of packages it would create. Specifically, if your package began with rust- or ended with -rs, Cargo would rename it. The intention was that well, it’s a Rust package, this information is redundant. However, people feel quite strongly about naming, and when they bump into this, they’re surprised and often upset. As such, we’re not going to do that any more.

Many users love cargo doc, a way to generate local documentation for their Cargo projects. It’s getting a huge speed boost in this release, as now, it uses cargo check, rather than a full cargo build, so some scenarios will get faster.

Additionally, checkouts of git dependencies should be a lot faster, thanks to the use of hard links when possible.

See the detailed release notes for more.

1358 contributors to this release.

Reproduced from the Rust blog under its publication licence. Typeset in Literata.