What would be the most efficient way of swapping halves of two vectors of owned values?
That is we have two vectors of the same type, I'd like to replace the second half of the vector
a with the second half of the vector
b, and, correspondingly, the second half of the
a (the original one) with the second half of the
a = [1,2,3,4,5,6]
b = [10, 20, 30, 40, 50, 60]
a = [1,2,3, 40, 50, 60]
b = [10, 20, 30, 4, 5, 6]
Because these are non-overlapping, I was hoping to make this in-place, without cloning (the real case uses large stucts, not numbers).
All I could come up with was something like
let a_mid = a.len() / 2; let b_mid = b.len() / 2; let r = a.splice(a_mid.., &b[b_mid..]); b.splice(b_mid.., r);
but it doesn't even compile