You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// end is a slice of everything but the first element, which must be "a"
91
+
92
+
//`end` is a slice of everything but the first element, which must be "a".
91
93
["a", end@..] =>println!("ends with: {:?}", end),
92
94
93
95
rest=>println!("{:?}", rest),
@@ -103,17 +105,17 @@ If you're interested in learning more, we published [a post on the Inside Rust b
103
105
This release of Rust stabilizes a new macro, [`matches!`](https://doc.rust-lang.org/nightly/std/macro.matches.html). This macro accepts an expression and a pattern, and returns true if the pattern matches the expression. In other words:
104
106
105
107
```rust
106
-
//with the match keyword
108
+
//Using a match expression:
107
109
matchself.partial_cmp(other) {
108
110
Some(Less) =>true,
109
111
_=>false,
110
112
}
111
113
112
-
//with the matches! macro
114
+
//Using the `matches!` macro:
113
115
matches!(self.partial_cmp(other), Some(Less))
114
116
```
115
117
116
-
You can also use features like `|` patterns and `if`clauses:
118
+
You can also use features like `|` patterns and `if`guards:
117
119
118
120
```rust
119
121
letfoo='f';
@@ -127,7 +129,7 @@ assert!(matches!(bar, Some(x) if x > 2));
127
129
128
130
In Rust 2018, we [removed the need for `extern crate`](https://doc.rust-lang.org/stable/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate). But procedural macros were a bit special, and so when you were writing a procedural macro, you still needed to say `extern crate proc_macro;`.
129
131
130
-
In this release, [you no longer need this line when working with the 2018 edition; you can use `use` like any other crate][cargo/7700]. Given that most projects will already have a line similar to `use proc_macro::TokenStream;`, this change will mean that you can delete the `extern crate proc_macro;` line and your code will still work. This change is small, but brings procedural macros closer to regular code.
132
+
In this release, if you are using Cargo, [you no longer need this line when working with the 2018 edition; you can use `use` like any other crate][cargo/7700]. Given that most projects will already have a line similar to `use proc_macro::TokenStream;`, this change will mean that you can delete the `extern crate proc_macro;` line and your code will still work. This change is small, but brings procedural macros closer to regular code.
131
133
132
134
### Libraries
133
135
@@ -160,8 +162,10 @@ We have two notable compatibility notes this release: a deprecation in the stand
160
162
161
163
Sometimes, mistakes are made. The `Error::description` method is now considered to be one of those mistakes. The problem is with its type signature:
162
164
163
-
fn description(&self) -> &str {
164
-
165
+
```rust
166
+
fndescription(&self) ->&str
167
+
```
168
+
165
169
Because `description` returnsa `&str`, itisnotnearlyasusefulaswewisheditwouldbe.Thismeansthatyoubasicallyneedtoreturnthecontentsofan `Error` verbatim; ifyouwantedtosay, use formatting to produce a nicer description, that is impossible: you'd need to return a `String`.Instead, error types should implement the `Display`/`Debug` traits to provide the description of the error.
166
170
167
171
ThisAPI has existed since Rust 1.0.We've been working towards this goal for a long time: back inRust 1.27, we ["soft deprecated" this method](https://github.com/rust-lang/rust/pull/50163). 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 as *actually* deprecated][66919], and took some steps to de-emphasize the method in `Error`'s documentation. Due to our stability policy, `description` will never be removed, and so this is as far as we can go.
@@ -172,4 +176,4 @@ Apple is no longer supporting 32-bit targets, and so, neither are we. They have
172
176
173
177
## Contributors to 1.42.0
174
178
175
-
Many people came together to create Rust 1.42.0. We couldn't have done it without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.42.0/)
179
+
Many people came together to create Rust 1.42.0.We couldn't have done it without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.42.0/)
0 commit comments