Hallo,
it would be very handy if the push_front() and it's corresponding push_back() method return the dropped element.
I have some logic which needs to clean up other stuff in the case an element gets dropped from a CircularBuffer:
let mut revisions = CircularBuffer::new()
...
if let Err(revision) = revisions.try_push_front(revision) {
if let Some(oldest_revision) = revisions.pop_back() {
self.store.remove(oldest_revision.hash());
}
revisions.try_push_front(revision)
.expect("After removing the oldest revision, the buffer should now have space to push a new revision.")
}
A fn push_front(&mut self, item: T) -> Option<T> method would reduce the code above to:
if let Some(oldest_revision) = revisions.push_front(revision) {
self.store.remove(oldest_revision.hash());
}
Hallo,
it would be very handy if the
push_front()and it's correspondingpush_back()method return the dropped element.I have some logic which needs to clean up other stuff in the case an element gets dropped from a CircularBuffer:
A
fn push_front(&mut self, item: T) -> Option<T>method would reduce the code above to: