Merge pull request #280 from Skandesh/patch-3

Update Vector.md
This commit is contained in:
Sunface 2022-07-28 09:06:06 +08:00 committed by GitHub
commit d0a8f0aabc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 0 deletions

View File

@ -28,6 +28,39 @@ fn main() {
}
fn is_vec(v: &Vec<u8>) {}
//Another solution
fn main() {
let arr: [u8; 3] = [1, 2, 3];
let v = Vec::from(arr);
is_vec(&v);
let v = vec![1, 2, 3];
is_vec(&v);
// vec!(..) and vec![..] are same macros, so
let v = vec!(1, 2, 3);
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 mut v1 = vec!();
for i in &v{
v1.push(*i);
}
is_vec(&v1);
assert_eq!(v, v1);
println!("Success!")
}
fn is_vec(v: &Vec<u8>) {}
```
2.