Skip to content

Instantly share code, notes, and snippets.

@carols10cents
Forked from anonymous/playground.rs
Created October 28, 2015 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carols10cents/6a30899ab8f14a119860 to your computer and use it in GitHub Desktop.
Save carols10cents/6a30899ab8f14a119860 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
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