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:
Scott Rhodes
2023-11-12 13:45:22 -05:00
committed by GitHub
parent 819d9d414a
commit 6990f89c16

View File

@ -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();
}
}
```
```