Rust 1.20 makes constants part of a type’s public interface The Rust team announced version 1.20.0 on August 31, 2017. Its headline language change was support for associated constants: a struct, enum, or trait can expose a constant through the type, and a trait can require each implementation to provide its value. That distinction matters for APIs that describe fixed values. Before associated constants, the release post explains, a trait representing floating-point values had to model values such as NaN and infinity as functions. Functions could not be used in constant expressions, so libraries needed parallel constants and functions. With the new feature, a trait can declare those values directly and each implementation supplies them. The change gives library authors a cleaner way to express type-level constants without pretending they are runtime operations. The release also brought standard-library and Cargo changes. Rust 1.20 stabilized three unstable sorting methods, which may reorder equal-key items; the team presented them as an option when callers do not need stable ordering. Cargo moved crates.io authentication tokens out of the commonly permissioned configuration file and into a separate credentials file that can use more restrictive permissions. The post also notes support for organizing larger secondary binaries under separate directories. The announcement’s practical message was incremental rather than a wholesale redesign: one new language building block, additional library APIs, and packaging and credential-handling improvements, all delivered in the stable release. [story-s1]
Source documents
- Announcing Rust 1.20https://blog.rust-lang.org/2017/08/31/Rust-1.20/
