Skip to content

Commit b21dd75

Browse files
committed
review feedback
1 parent 47a46c6 commit b21dd75

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

_posts/2017-10-12-Rust-1.21.md

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ In Rust, this code is synonymous with:
3535

3636
```rust
3737
let _x = 5;
38-
let x = &x;
38+
let x = &_x;
3939
```
4040

4141
That is, the `5` here will be stored on the stack, or possibly in registers.
@@ -111,19 +111,19 @@ the platform we build the documentation on. We've long regretted that the hosted
111111
version of the documentation has been Linux-specific; this is a first step towards
112112
rectifying that. This is [specific to the standard
113113
library](https://github.com/rust-lang/rust/pull/43348) and not for general use;
114-
we'll hope to improve this further in the future.
114+
we hope to improve this further in the future.
115115

116116
Next, [Cargo's docs are moving!](https://github.com/rust-lang/rust/pull/43916)
117117
Historically, Cargo's docs were hosted on doc.crates.io, which doesn't follow
118-
the release train model, even though Cargo itself does. This lead to situations
118+
the release train model, even though Cargo itself does. This led to situations
119119
where a feature would land in Cargo nightly, the docs would be updated, and
120120
then for up to twelve weeks, users would *think* that it should work, but it
121121
wouldn't yet. [https://doc.rust-lang.org/cargo](https://doc.rust-lang.org/cargo)
122122
will be the new home of Cargo's docs, though for now, that URL is a redirect to
123123
doc.crates.io. Future releases will move Cargo's docs over, and at that point,
124124
doc.crates.io will redirect to doc.rust-lang.org/cargo. Cargo's docs have long
125125
needed a refreshing, so expect to hear more news about Cargo's docs generally
126-
through the end of the year.
126+
in the future!
127127

128128
Finally, until now, `rustdoc` did not have any documentation. This is now
129129
[fixed](https://github.com/rust-lang/rust/pull/43863), with a new "`rustdoc`
@@ -146,13 +146,50 @@ recently](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics
146146
which may help with this situation. That change has yet to be implemented, however,
147147
though pre-requisite work is ongoing at the moment.
148148

149+
Next, [`Iterator::for_each`](https://github.com/rust-lang/rust/pull/44567) has
150+
been stabilized, letting you consume an iterator for side effects without needing
151+
a `for` loop:
152+
153+
```rust
154+
// old
155+
for i in 0..10 {
156+
println!("{}", i);
157+
}
158+
159+
// new
160+
(0..10).for_each(|i| println!("{}", i));
161+
```
162+
163+
The correct one to use depends on your situation; in the sample above, the `for` loop
164+
is pretty striaghtforward. But when you're chaining a number of iterators together,
165+
the `for_each` version is sometimes clearer. Consider this:
166+
167+
```rust
168+
// old
169+
for i in (0..100).map(|x| x + 1).filter(|x| x % 2 == 0) {
170+
println!("{}", i);
171+
}
172+
173+
// new
174+
(0..100)
175+
.map(|x| x + 1)
176+
.filter(|x| x % 2 == 0)
177+
.for_each(|i| println!("{}", i));
178+
```
179+
149180
[`Rc<T>` and `Arc<T>` now implement `From<&[T]> where T: Clone`, `From<str>`,
150181
`From<String>`, `From<Box<T>> where T: ?Sized`, and
151182
`From<Vec<T>>`.](https://github.com/rust-lang/rust/pull/42565)
152183

184+
The [`max` and `min` functions on the `Ord`
185+
trait](https://github.com/rust-lang/rust/pull/44593) are now stable.
186+
187+
The [`needs_drop` intrinsic](https://github.com/rust-lang/rust/pull/44639)
188+
is now stable.
189+
153190
Finally, [`std::mem::discriminant` has been
154191
stabilized](https://doc.rust-lang.org/std/mem/fn.discriminant.html), allowing
155-
you to see what variant an `enum` is.
192+
you to see what variant an `enum` instance is without a `match` statement.
156193

157194
See the [detailed release notes][notes] for more.
158195

0 commit comments

Comments
 (0)