diff --git a/solutions/collections/Vector.md b/solutions/collections/Vector.md index 903405a..bda978d 100644 --- a/solutions/collections/Vector.md +++ b/solutions/collections/Vector.md @@ -28,6 +28,39 @@ fn main() { } fn is_vec(v: &Vec) {} + + +//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 + // 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) {} + ``` 2. @@ -215,4 +248,4 @@ fn main() { ip.display(); } } -``` \ No newline at end of file +```