Skip to content

Commit ce28351

Browse files
committed
added quotes in impl_trait
1 parent ba3bba8 commit ce28351

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
- [Operator Overloading](trait/ops.md)
138138
- [Drop](trait/drop.md)
139139
- [Iterators](trait/iter.md)
140-
- [impl Trait](trait/impl_trait.md)
140+
- [`impl Trait`](trait/impl_trait.md)
141141
- [Clone](trait/clone.md)
142142

143143
- [macro_rules!](macros.md)

src/trait/impl_trait.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# impl Trait
1+
# `impl Trait`
22

3-
If your function returns a type that implements `MyTrait`, you can write its return type as `-> impl MyTrait`. This can help simplify your type signatures quite a lot!
3+
If your function returns a type that implements `MyTrait`, you can write its
4+
return type as `-> impl MyTrait`. This can help simplify your type signatures quite a lot!
45

56
```rust,editable
67
use std::iter;
78
use std::vec::IntoIter;
89
9-
// This function combines two Vec<i32> and returns an iterator over it.
10+
// This function combines two `Vec<i32>` and returns an iterator over it.
1011
// Look how complicated its return type is!
1112
fn combine_vecs_explicit_return_type<'a>(
1213
v: Vec<i32>,
@@ -25,7 +26,10 @@ fn combine_vecs<'a>(
2526
}
2627
```
2728

28-
More importantly, some Rust types can't be written out. For example, every closure has its own unnamed concrete type. Before `impl Trait` syntax, you had to allocate on the heap in order to return a closure. But now you can do it all statically, like this:
29+
More importantly, some Rust types can't be written out. For example, every
30+
closure has its own unnamed concrete type. Before `impl Trait` syntax, you had
31+
to allocate on the heap in order to return a closure. But now you can do it all
32+
statically, like this:
2933

3034
```rust,editable
3135
// Returns a function that adds `y` to its input
@@ -40,7 +44,10 @@ fn main() {
4044
}
4145
```
4246

43-
You can also use `impl Trait` to return an iterator that uses `map` or `filter` closures! This makes using `map` and `filter` easier. Because closure types don't have names, you can't write out an explicit return type if your function returns iterators with closures. But with `impl Trait` you can do this easily:
47+
You can also use `impl Trait` to return an iterator that uses `map` or `filter`
48+
closures! This makes using `map` and `filter` easier. Because closure types don't
49+
have names, you can't write out an explicit return type if your function returns
50+
iterators with closures. But with `impl Trait` you can do this easily:
4451

4552
```rust,editable
4653
fn double_positives<'a>(numbers: &'a Vec<i32>) -> impl Iterator<Item = i32> + 'a {
@@ -49,4 +56,4 @@ fn double_positives<'a>(numbers: &'a Vec<i32>) -> impl Iterator<Item = i32> + 'a
4956
.filter(|x| x > &&0)
5057
.map(|x| x * 2)
5158
}
52-
```
59+
```

0 commit comments

Comments
 (0)