`push_front` and `push_back` should return dropped element
kKdH opened this issue · 3 comments
kKdH commented
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());
}
andreacorbellini commented
Hi, this feature was already contributed in #3. Because this is a backward-incompatible change, I could not release it in 0.1.x, so I'm holding it off until a future 0.2.x release. I plan to make such 0.2.x release within the next 2-3 months, so stay tuned!
andreacorbellini commented
Yes, that's coming too in the same release.
…On Mon, Jan 29, 2024, 00:54 Elmar Schug ***@***.***> wrote:
Thank you! Sounds great. That in combination with #8
<#8> would
be awesome!
—
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACOKLR4BHF75V4N5OI2JZ3YQ5PUVAVCNFSM6AAAAABCK2PHBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJUGIZTIMBWGI>
.
You are receiving this because you commented.Message ID:
***@***.***>