-
Notifications
You must be signed in to change notification settings - Fork 22
Closed
Labels
ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)API Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries
Description
Proposal
Problem statement
It would be convenient if LinkedList had retain/retain_mut methods just like many other collections. We can migrate between different collections easily.
Motivating examples or use cases
When implementing MVCC transactions in database, it's very common to store the active transactions as a list. They'll be garbage collected by a monotonic version.
txn.version > gc_versionlet mut active_txns = LinkedList::new();;
let mut gc_version = 0;
// ...
while gc_triggerer.next() {
active_txns.retain(|&txn| txn.version > gc_version);
}
In fact, there are similar use cases like other collections.
Solution sketch
pub struct LinkedList;
impl LinkedList {
pub fn retain_mut<F>(&mut self, mut f: F)
where
F: FnMut(&mut T) -> bool;
pub fn retain<F>(&mut self, mut f: F)
where
F: FnMut(&T) -> bool;
}
Alternatives
Links and related work
Metadata
Metadata
Assignees
Labels
ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)API Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries