Vec delete-move

  1. We have a type T where: T has Drop. T does NOT have clone/copy.

  2. We have ans : Vec<T>, and ans.len() = 100

  3. Is there a way to perform the following operation:

drop ans[3];
ans[3] = ans[99];
ans.len() = 99;

This is Vec::swap_remove, I believe. The drop will occur when the returned value goes out of scope, so not strictly in the order you listed…

2 Likes

swap_remove is indeed what I want. Thanks!

1 Like