BT

Rust 1.20 Brings Associated Constants and More

| by Sergio De Simone Follow 14 Followers on Sep 08, 2017. Estimated reading time: 1 minute |

Rust 1.20 adds type-associated constants, a number of library stabilization, and improved credential hiding in Cargo.

Rust 1.20 allows now to define constants associated to traits, structs, and enums. For example, the following snippet defines an ID constant that is not associated to any particular instance and can be used as Struct::ID:

struct Struct;

impl Struct {
    const ID: u32 = 0;
}

When defining an associated constant for a trait, you are not required to define a value for it, letting the concrete trait implementation do it:

trait Trait {
    const ID: u32;
}

struct Struct;

impl Trait for Struct {
    const ID: u32 = 5;
}

Additionally, Rust 1.20 fixes a number of bugs that affected macros, specifically by attempting to predict whether a token can be matched against a fragment specifier. The Rust compiler has also been improved by improving type coercion within structs, enabling the LLVM WebAssembly backend, improving error messages, and more.

On the standard library front, Rust 1.20 introduced a number of improvements and stabilizations:

  • The unimplemented! macro allows now to specify an informative message.
  • min and max have been rewritten in Rust.
  • Runtime guarantees have been improved by providing stack probes, which make sure a stack overflow will trigger a segfault instead of being accidentally ignored; and better integration with Linux stack guard mechanism, which were introduced to fix a vulnerability in the kernel.
  • Unstable sort functions are now available through slice::sort_unstable_by_key, slice::sort_unstable_by, and slice::sort_unstable. Unstable sorting does not guarantee that equally-ranking items will always appear in the same order when they are sorted multiple times, which makes it usually faster and easier to code.

Finally, Rust package manager Cargo now stores the crates.io authentication token in a separate file, named ~/.cargo/credentials, which can be properly protected from other users attempting to access it.

To get the full detail of what is new in Rust 1.20, do not forget to read the release notes.

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