1

I have a vector of vectors. I would like to transform it into a vector of slices without creating a new object:

let mut a: Vec<Vec<u8>> = vec![vec![0; 8]; msg.len()];
let mut new: Vec<&[u8]> = Vec::new();

for i in 0..a.len() {
    a[i] = foo(i);
}

for i in 0..a.len() {
    new.push(&a[i]);
}

Is it possible?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
captain_flammy
  • 117
  • 3
  • 9
  • No, it is not possible. – Shepmaster Feb 27 '20 at 01:40
  • In addition to what is said in the duplicate, remember that slices only _borrow_ the data they point to and ask yourself who would _own_ that data once you replaced the original vectors? – Jmb Feb 27 '20 at 08:19

0 Answers0