-
-
Save carols10cents/6a30899ab8f14a119860 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
// I don't want this to have to be mut. | |
let v = vec![1, 2, 3]; | |
// Not this either. | |
let w = vec![3, 4, 5]; | |
// I want a newly allocated vec that is v + w. | |
let x = vec_concat(&v, &w); | |
println!("{:?}", x); | |
} | |
fn vec_concat(vec1: &Vec<i32>, vec2: &Vec<i32>) -> Vec<i32> { | |
let mut result = vec1.clone(); | |
result.extend(vec2.iter().cloned()); | |
result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment