Series: The Rust Annals
Vol. I Issue 63 nlopes.dev
Announcing Rust 1.62.0
Stabilizes widely used stdlib APIs like bool::then_some and total_cmp, introduces cargo add, and promotes x86_64-unknown-none to Tier 2, marking a highly impactful incremental release.
cargo add
You can now add new dependencies directly from the command line using cargo add. This command supports specifying features and versions. It can also be used to modify existing dependencies.
For example:
cargo add log
cargo add serde --features derive
cargo add nom@5
See the cargo documentation for more.
#[default] enum variants
You can now use #[derive(Default)] on enums if you specify a default variant. For example, until now you would have to manually write a Default impl for this enum:
#[derive(Default)]
enum Maybe<T> {
#[default]
Nothing,
Something(T),
}
As of now only “unit” variants (variants that have no fields) are allowed to be marked #[default]. More information is available in the RFC for this feature.
Thinner, faster mutexes on Linux
Previously, Mutex, Condvar, and RwLock were backed by the pthreads library on Linux. The pthreads locks support more features than the Rust APIs themselves do, including runtime configuration, and are designed to be used in languages with fewer static guarantees than Rust provides.
The mutex implementation, for example, is 40 bytes and cannot be moved. This forced the standard library to allocate a Box behind the scenes for each new mutex for platforms that use pthreads.
Rust’s standard library now ships with a raw futex-based implementation of these locks on Linux, which is very lightweight and doesn’t require extra allocation. In 1.62.0 Mutex only needs 5 bytes for its internal state on Linux, though this may change in future versions.
This is part of a long effort to improve the efficiency of Rust’s lock types, which includes previous improvements on Windows such as unboxing its primitives. You can read more about that effort in the tracking issue.
Bare metal x86_64 target
It’s now easier to build OS-less binaries for x86_64, for example when writing a kernel. The x86_64-unknown-none target has been promoted to Tier 2 and can be installed with rustup.
$ rustup target add x86_64-unknown-none
$ rustc --target x86_64-unknown-none my_no_std_program.rs
You can read more about development using no_std in the Embedded Rust book.