@@ -9,7 +9,7 @@ use std::vec::IntoIter;
9
9
10
10
// This function combines two `Vec<i32>` and returns an iterator over it.
11
11
// Look how complicated its return type is!
12
- fn combine_vecs_explicit_return_type<'a> (
12
+ fn combine_vecs_explicit_return_type(
13
13
v: Vec<i32>,
14
14
u: Vec<i32>,
15
15
) -> iter::Cycle<iter::Chain<IntoIter<i32>, IntoIter<i32>>> {
@@ -18,12 +18,24 @@ fn combine_vecs_explicit_return_type<'a>(
18
18
19
19
// This is the exact same function, but its return type uses `impl Trait`.
20
20
// Look how much simpler it is!
21
- fn combine_vecs<'a> (
21
+ fn combine_vecs(
22
22
v: Vec<i32>,
23
23
u: Vec<i32>,
24
24
) -> impl Iterator<Item=i32> {
25
25
v.into_iter().chain(u.into_iter()).cycle()
26
26
}
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
+ }
27
39
```
28
40
29
41
More importantly, some Rust types can't be written out. For example, every
0 commit comments