Merge pull request #476 from Scott169/master

Correction of problem 1 in vector.md
This commit is contained in:
Sunface
2023-12-07 20:13:48 +08:00
committed by GitHub

View File

@ -9,26 +9,26 @@ fn main() {
let arr: [u8; 3] = [1, 2, 3]; let arr: [u8; 3] = [1, 2, 3];
let v = Vec::from(arr); let v = Vec::from(arr);
is_vec(v); is_vec(&v);
let v = vec![1, 2, 3]; let v = vec![1, 2, 3];
is_vec(v); is_vec(&v);
// vec!(..) and vec![..] are same macros, so // vec!(..) and vec![..] are same macros, so
let v = vec!(1, 2, 3); let v = vec!(1, 2, 3);
is_vec(v); is_vec(&v);
// In code below, v is Vec<[u8; 3]> , not Vec<u8> // In code below, v is Vec<[u8; 3]> , not Vec<u8>
// USE Vec::new and `for` to rewrite the below code // USE Vec::new and `for` to rewrite the below code
let v1 = vec!(arr); let v1 = vec!(arr);
is_vec(v1); is_vec(&v1);
assert_eq!(v, v1); assert_eq!(v, v1);
println!("Success!"); println!("Success!");
} }
fn is_vec(v: Vec<u8>) {} fn is_vec(v: &Vec<u8>) {}
``` ```
@ -241,4 +241,4 @@ fn main() {
ip.display(); ip.display();
} }
} }
``` ```