-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Closed
Labels
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
I saw issue #61129, and thought that it might be a good idea to generalize it.
The prelude could export a new trait called Take.
pub trait Take {
fn take(&mut self) -> Self;
}A lot of types could implement it, Vec<T> for example. The take method on Option<T> could be moved into this trait, etc.
The Take trait could even be implemented for every type that implements Default:
impl<T> Take for T
where
T: Default
{
fn take(&mut self) -> Self {
mem::replace(self, Default::default())
}
}Metadata
Metadata
Assignees
Labels
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.