-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.
Description
Sometimes I want to take a single element from a Vec
and throw the rest of the Vec
away. I can do this using swap_remove
then dropping the Vec
(or letting it fall out of scope) but it would be clearer and slightly more efficient if there was a method for doing this directly.
I propose adding this method to Vec
:
impl<T> Vec<T> {
/// Take a single element of a vector and return it, consuming the
/// vector. If `index` is invalid the original vector is returned.
pub fn into_element(self, index: usize) -> Result<T, Vec<T>> {
...
}
}
MOZGIII, DevNulPavel, robsdedude and EdJoPaTo
Metadata
Metadata
Assignees
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.