@@ -44,12 +44,12 @@ collection.
44
44
``` rust, editable
45
45
let names = vec!["Bob", "Frank", "Ferris"];
46
46
47
- for name in names.iter() {
48
- match name {
49
- &"Ferris" => println!("There is a rustacean among us!"),
50
- _ => println!("Hello {}", name),
51
- }
47
+ for name in names.iter() {
48
+ match name {
49
+ &"Ferris" => println!("There is a rustacean among us!"),
50
+ _ => println!("Hello {}", name),
52
51
}
52
+ }
53
53
```
54
54
55
55
* ` into_iter ` - This consumes the collection so that on each iteration the exact
@@ -60,11 +60,11 @@ let names = vec!["Bob", "Frank", "Ferris"];
60
60
let names = vec!["Bob", "Frank", "Ferris"];
61
61
62
62
for name in names.into_iter() {
63
- match name {
64
- "Ferris" => println!("There is a rustacean among us!"),
65
- _ => println!("Hello {}", name),
66
- }
63
+ match name {
64
+ "Ferris" => println!("There is a rustacean among us!"),
65
+ _ => println!("Hello {}", name),
67
66
}
67
+ }
68
68
```
69
69
70
70
* ` iter_mut ` - This mutably borrows each element of the collection, allowing for
@@ -74,11 +74,11 @@ for name in names.into_iter() {
74
74
let mut names = vec!["Bob", "Frank", "Ferris"];
75
75
76
76
for name in names.iter_mut() {
77
- match name {
78
- &mut "Ferris" => println!("There is a rustacean among us!"),
79
- _ => println!("Hello {}", name),
80
- }
77
+ match name {
78
+ &mut "Ferris" => println!("There is a rustacean among us!"),
79
+ _ => println!("Hello {}", name),
81
80
}
81
+ }
82
82
```
83
83
84
84
In the above snippets note the type of ` match ` branch, that is the key
0 commit comments