Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Rust 1.31 is out with stable Rust 2018

Save for later
  • 3 min read
  • 07 Dec 2018

article-image

Yesterday, Rust 1.31.0 and Rust 2018 was announced in the official blog of the programming language. Rust 1.31.0 is the first stable iteration of Rust 2018 and many features in this version are now stable.

Rust 2018


Rust 2018 brings all of the work that the Rust team has been doing since 2015 to create a cohesive package. This goes beyond just language features and includes tooling, documentation, domain working groups work, and a new website.

Each Rust package can be in either Rust 2015 or Rust 2018 and they work seamlessly together. Projects made in Rust 2018 can use dependencies from 2015, and a 2015 project can use 2018 dependencies. This is done so that the ecosystem doesn't split. The new features are opt-in to preserve compatibility in existing code.

Non-lexical lifetimes


Non-lexical lifetimes or NLL simply means that the borrow checker is now smarter, and accepts some valid code that was rejected by it previously.

Module system changes


People new to Rust struggle with its module system. Even if there are simple and consistent rules that define the module system, their consequences can come across as inconsistent, counterintuitive and mysterious. Hence Rust 2018 introduces a few changes to how paths work. These changes ended up simplifying the module system, and now there is better clarity as to what is going on in the module system.

More lifetime elision rules


Some additional elision rules for impl blocks and function definitions are added. For example:

impl<'a> Reader for BufReader<'a> {

   // methods go here

}

This can now be written like this:

impl Reader for BufReader<'_> {

   // methods go here

}

Lifetimes still need to be defined in structs. But now no longer require as much boilerplate as before.

const fn


There are many ways to define a function in Rust.

  • A regular function with fn
  • An unsafe function with unsafe fn
  • An external function with extern fn


Rust 1.31 adds a new way to qualify a function: const fn.

New tools in Rust 1.31


Tools like Cargo, Rustdoc, and Rustup have been crucial in Rust since version 1.0. In Rust 2018, a new generation of tools are ready for all users—

  • Clippy: Rust's linter.
  • Unlock access to the largest independent learning library in Tech for FREE!
    Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
    Renews at ₹800/month. Cancel anytime
  • Rustfmt: A tool for formatting Rust code.
  • IDE support: Rust is now supported in popular IDEs like Visual Studio Code, IntelliJ, Atom, Sublime Text 3, Eclipse.

Tool lints


"tool attributes", like #[rustfmt::skip] were stabilized in Rust 1.30. In Rust 1.31, "tool lints," like #[allow(clippy::bool_comparison)] are being stabilized. These give a namespace to lints making their tool of origin more clear.

Other additions


Apart from changes in the language itself, there are changes to other areas too.

  • Documentation: "The Rust Programming Language" book has been rewritten.
  • Domain working groups: Four new domain working groups are introduced—network services, command-line applications, WebAssembly, embedded devices.
  • New website: There’s a new iteration of the website for Rust 2018.
  • Library stabilizations: Some From implementations have been added to stabilize libraries.
  • Cargo changes: In Rust 1.31 cargo will download packages in parallel using HTTP/2.



Rust Survey 2018 key findings: 80% developers prefer Linux, WebAssembly growth doubles, and more

Rust Beta 2018 is here

GitHub Octoverse: The top programming languages of 2018