Closed
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;
}