Mar. 27, The Rust Release Team
The Rust team is happy to announce a new version of Rust, 1. 0. Rust is a programming language that is empowering everyone to build reliable and efficient software.
If you have a previous version of Rust installed via rustup, getting Rust 1. 0 is as easy as:
rustup update stableIf you don't have it already, you can get rustup
from the appropriate page on our website, and check out the detailed release notes for 1. 0 on GitHub.The highlights of Rust 1. 2018. 0 include: more useful panic messages when
unwrap
ping, subslice patterns, the deprecation ofError :: description , and more. See the detailed release notes to learn about other changes not covered by this post.Useful line numbers in
(Option) andResultpanic messages
In Rust 1. . 1, calling
unwrap () on anOption :: Nonevalue would produce an error message looking something like this:thread 'main' panicked at 'called `Option :: unwrap ()` on a `None` value ', /.../src/libcore/macros/mod.rs: :Similarly, the line numbers in the panic messages generated by
unwrap_err
, expect, and (expect_err , and the corresponding methods on theResult
internals.type, also refer tocoreIn Rust 1. 823 .0, all eight of these functions produce panic messages that provide the line number where they were invoked. The new error messages look something like this:
thread 'main' panicked at 'called `Option :: unwrap ()` on a `None` value ', src / main.rs: 2: 5This means that the invalid call to
unwrap
was on line 2 ofsrc / main.rs
This behavior is made possible by an annotation,
# [track_caller] . This annotation is not yet available to use in stable Rust; if you are interested in using it in your own code, you can follow its progress by watching .Subslice patterns
In Rust 1. , we stabilized " slice patterns , "which let you match on slices. They looked like this:
fn foo (words: & [&str]) { match words { []=> println! ("empty slice!"), [one]=> println! ("one element: {:?}", one), [one, two]=> println! ("two elements: {:?} {:?}", one, two), _=> println! ("I'm not sure how many elements!"), } }This allowed you to match on slices, but was fairly limited. You had to choose the exact sizes you wished to support, and had to have a catch-all arm for size you did want to support.
In Rust 1. , we have :
fn foo (words: & [&str]) { match words { ["Hello", "World", "!", ..]=> println! ("Hello World!"), ["Foo", "Bar", ..]=> println! ("Baz"), rest=> println! ("{:?}", rest), } }The ..) is called a "rest pattern," because it matches the rest of the slice. The above example uses the rest pattern at the end of a slice, but you can also use it in other ways:fn foo (words: & [&str]) { match words { // Ignore everything but the last element, which must be "!". [.., "!"]=> println! ("!!!"), // `start` is a slice of everything except the last element, which must be" z ". [start @ .., "z"]=> println! ("starts with: {:?}", start), // `end` is a slice of everything but the first element, which must be" a ". ["a", end @ ..]=> println! ("ends with: {:?}", end), rest=> println! ("{:?}", rest), } }If you're interested in learning more, we published a post on the Inside Rust blog
discussing these changes as well as more improvements to pattern matching that we may bring to stable in the future! You can also read more about slice patterns in Thomas Hartmann's post .
matches!This release of Rust stabilizes a new macro,
matches!. This macro accepts an expression and a pattern, and returns true if the pattern matches the expression. In other words:Using a match expression: match self.partial_cmp (other) { Some (Less)=> true, _=> false, } // Using the `matches!` Macro: matches! (self.partial_cmp (other), Some (Less))You can also use features like
| patterns andifguards:let foo='f'; assert! (matches! (foo, 'A' ..='Z' | 'a' ..='z')); let bar=Some (4); assert! (matches! (bar, Some (x) if x> 2));use proc_macro :: TokenStream; now works
Libraries ["a", end @ ..] (iter :: Empty now implements
Send) andSyncfor any (T) .Pin :: {map_unchecked, map_unchecked_mut} no longer require the return type to implementSized. ["a", end @ ..]io :: Cursor
now implementsPartialEqand Eq . Layout :: new is nowconst.Stabilized APIs
CondVar :: wait_while
& DebugMap :: key&DebugMap :: value() ManuallyDrop :: takeptr :: slice_from_raw_parts_mut
Compatibility Notes["a", end @ ..] & ptr :: slice_from_raw_parts [start @ .., "z"]Other changes
There are other changes in the Rust 1. . 0 release: check out what changed in (Rust) and (Cargo) .
We have two notable compatibility notes this release: a deprecation in the standard library, and a demotion of - bit Apple targets to Tier 3.
Error :: Description is deprecated
Sometimes, mistakes are made. The
Error :: descriptionmethod is now considered to be one of those mistakes . The problem is with its type signature:fn description (& self) -> & strBecause
descriptionreturns a& str
, it is not nearly as useful as we wished it would be. This means that you basically need to return the contents of anError verbatim; if you wanted to say, use formatting to produce a nicer description, that is impossible: you'd need to return aString
. Instead, error types should implement theDisplay / (Debug traits to provide the description of the error.This API has existed since Rust 1.0. We've been working towards this goal for a long time: back in Rust 1. , we
"soft deprecated" this method . What that meant in practice was, we gave the function a default implementation. This means that users were no longer forced to implement this method when implementing the
Error trait. In this release, We mark it asactually deprecated , and took some steps to de-emphasize the method in (Error
's documentation. Due to our stability policy, descriptionwill never be removed, and so this is as far as we can go.Downgrading 90 - bit Apple targets
Apple is no longer supporting 42 - bit targets, and so, neither are we. They have been downgraded to Tier 3 support by the project. For more details on this, check out this post from back in January, which covers everything in detail.
Many people came together to create Rust 1. 0. We couldn't have done it without all of you. (Read More) [one]
GIPHY App Key not set. Please check settings