mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 12:39:42 +00:00
Correction of problem 1 in vector.md
```v1``` cannot be referred if the ownership of ```v``` is moved to ```fn is_vec(v: &Vec<u8>)```
This commit is contained in:
@ -9,26 +9,26 @@ fn main() {
|
||||
let arr: [u8; 3] = [1, 2, 3];
|
||||
|
||||
let v = Vec::from(arr);
|
||||
is_vec(v);
|
||||
is_vec(&v);
|
||||
|
||||
let v = vec![1, 2, 3];
|
||||
is_vec(v);
|
||||
is_vec(&v);
|
||||
|
||||
// vec!(..) and vec![..] are same macros, so
|
||||
let v = vec!(1, 2, 3);
|
||||
is_vec(v);
|
||||
is_vec(&v);
|
||||
|
||||
// In code below, v is Vec<[u8; 3]> , not Vec<u8>
|
||||
// USE Vec::new and `for` to rewrite the below code
|
||||
let v1 = vec!(arr);
|
||||
is_vec(v1);
|
||||
is_vec(&v1);
|
||||
|
||||
assert_eq!(v, v1);
|
||||
|
||||
println!("Success!");
|
||||
}
|
||||
|
||||
fn is_vec(v: Vec<u8>) {}
|
||||
fn is_vec(v: &Vec<u8>) {}
|
||||
```
|
||||
|
||||
|
||||
@ -241,4 +241,4 @@ fn main() {
|
||||
ip.display();
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
Reference in New Issue
Block a user