Skip to content

Commit b8772b3

Browse files
authored
Merge pull request #1300 from jduan/master
Remove unnecessary lifetime annotation
2 parents 30506fa + dcf37b6 commit b8772b3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/trait/impl_trait.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::vec::IntoIter;
99
1010
// This function combines two `Vec<i32>` and returns an iterator over it.
1111
// Look how complicated its return type is!
12-
fn combine_vecs_explicit_return_type<'a>(
12+
fn combine_vecs_explicit_return_type(
1313
v: Vec<i32>,
1414
u: Vec<i32>,
1515
) -> iter::Cycle<iter::Chain<IntoIter<i32>, IntoIter<i32>>> {
@@ -18,12 +18,24 @@ fn combine_vecs_explicit_return_type<'a>(
1818
1919
// This is the exact same function, but its return type uses `impl Trait`.
2020
// Look how much simpler it is!
21-
fn combine_vecs<'a>(
21+
fn combine_vecs(
2222
v: Vec<i32>,
2323
u: Vec<i32>,
2424
) -> impl Iterator<Item=i32> {
2525
v.into_iter().chain(u.into_iter()).cycle()
2626
}
27+
28+
fn main() {
29+
let v1 = vec![1, 2, 3];
30+
let v2 = vec![4, 5];
31+
let mut v3 = combine_vecs(v1, v2);
32+
assert_eq!(Some(1), v3.next());
33+
assert_eq!(Some(2), v3.next());
34+
assert_eq!(Some(3), v3.next());
35+
assert_eq!(Some(4), v3.next());
36+
assert_eq!(Some(5), v3.next());
37+
println!("all done");
38+
}
2739
```
2840

2941
More importantly, some Rust types can't be written out. For example, every

0 commit comments

Comments
 (0)