addressed review comments - grammar corrections, space additions
This commit is contained in:
parent
9bf73d24d0
commit
a3c9afa841
@ -114,30 +114,37 @@ for i in v {
|
||||
println!("Take ownership of the vector and its element {}", i);
|
||||
}
|
||||
```
|
||||
Note: You cannot use the vector again once you have iterated with ownership of the vector.
|
||||
You can iterate the vector multiple times with reference iteration. For example, the following
|
||||
code does not compile.
|
||||
|
||||
Note: You cannot use the vector again once you have iterated by taking ownership of the vector.
|
||||
You can iterate the vector multiple times by taking a reference to the vector whilst iterating.
|
||||
For example, the following code does not compile.
|
||||
|
||||
```rust
|
||||
let mut v = vec![1, 2, 3, 4, 5];
|
||||
|
||||
for i in v {
|
||||
println!("Take ownership of the vector and its element {}", i);
|
||||
}
|
||||
|
||||
for i in v {
|
||||
println!("Take ownership of the vector and its element {}", i);
|
||||
}
|
||||
```
|
||||
|
||||
Whereas the following works perfectly,
|
||||
|
||||
```rust
|
||||
let mut v = vec![1, 2, 3, 4, 5];
|
||||
|
||||
for i in &v {
|
||||
println!("A mutable reference to {}", i);
|
||||
println!("This is a reference to {}", i);
|
||||
}
|
||||
|
||||
for i in &v {
|
||||
println!("A mutable reference to {}", i);
|
||||
println!("This is a reference {}", i);
|
||||
}
|
||||
```
|
||||
|
||||
Vectors have many more useful methods, which you can read about in [their
|
||||
API documentation][vec].
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user