-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
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
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.