-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking Issue for vec::Drain{,Filter}::keep_rest #101122
Copy link
Copy link
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-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.
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Feature gate:
#![feature(drain_keep_rest)]This is a tracking issue for
vec::Drain::keep_rest, methods allowing to keep elements in aVecafter draining some of them.Public API
Steps / History
vec::Drain{,Filter}::keep_rest#95376Unresolved Questions
.drain_filter(f).take(N)works as expectedDropforDraindrain_filter) then you'd need to write.foreach(drop)to explicitly drop all the rest of the range that matches the filter.&mut selfinstead ofself?Draininside a struct and are operating on it from a&mut selfmethod of the struct,keep_rest(self)is impossible to use. :(mem::replace(&mut self.drain_filter, Vec::new().drain(..)).keep_rest()but the borrow checker won't like that.Drainfield toOption<Drain>and useself.drain_filter.take().unwrap().keep_rest()along withunwrap()everywhere else that the drain is used. Not good..next()returnsNone.next()panic!s.keep_rest()sets a flag inside theDrainwhichDropwill use to decide its behavior, and you're free to continue accessing iterator elements in between.const EXHAUST_ON_DROP: bool = trueconst generic parameter&mut Drain<'a, T, A, false>from the beginningFootnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩