0

I have an array of vectors, and I wish to copy a slice from a vector at one index into a vector at a different index.

I make sure the indices are different:

for ins in instructions.iter() {
    let n = a[ins.from].len();
    if ins.to == ins.from { continue; }
    unsafe {  // <-- Tried adding unsafe to convince rust I know it's ok... 
        let x = &a[ins.from][n - ins.num_to_move..];
        a[ins.to].copy_from_slice(x);
    }
    a[ins.from].truncate(ins.num_to_move);
}

where a is mut [Vec<u8>; 9].

How do I achieve this efficiently (i.e. with just one memcpy per instruction iteration)?

feature_engineer
  • 1,088
  • 8
  • 16

0 Answers0