Closed
Description
A slice method similar to slice::get_unchecked_mut that could be added:
#[inline]
pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize) {
unsafe {
// Can't take two mutable loans from one vector, so instead
// just cast them to their raw pointers to do the swap.
let pa: *mut T = self.get_unchecked_mut(a);
let pb: *mut T = self.get_unchecked_mut(b);
ptr::swap(pa, pb);
}
}
To be added to the std lib only if there's enough usage for this method.
See also:
https://crates.io/crates/unchecked-index