0

I want to add two Vectors which will give me another vector as a result without mutation of the existing ones:

I found a related question, but it does mutate the first one, which I don't want.
Best way to concatenate vectors in Rust

let vec1: Vec<i32> = vec![1, 2, 3];
let vec2: Vec<i32> = vec![4, 5, 6];
let vec3: Vec<i32> = ??; // expected vector equal to vec![1, 2, 3, 4, 5, 6];
hellow
  • 12,430
  • 7
  • 56
  • 79
Damian Dziaduch
  • 2,107
  • 1
  • 15
  • 16
  • What prevents you from creating a new `Vec` (with `vec![]`) and applying the answer you have linked to that created vec? – hellow Jun 07 '19 at 06:13
  • @hellow I am doing Code Kata - implement a Deadfish. I have a match which returns tuple (i32, Vec) in each arm, but one of arms is adding the element to the Vector. I'd like to express it as `'o' => (value, result + !vec[value])` but it does not work... Here is my code: https://pastebin.com/6NZZCyit – Damian Dziaduch Jun 07 '19 at 06:33
  • Please answer my question... what prevents you from creating a new vec and doing the very same as in your linked answer to that newly created vec? – hellow Jun 07 '19 at 06:35
  • @hellow I can't make it in one line. Or maybe I am missing something. Please see my pastebin code, lines 8-11. I'd like to make it in one statement – Damian Dziaduch Jun 07 '19 at 07:34
  • What is so wrong in using multiple lines if the code gets cleaner? Sorry, but doing it in one line, is nothing one should enforce. – hellow Jun 07 '19 at 07:43

0 Answers0