Add retain_back (aka truncate_front) method to Deque#663
Conversation
zeenix
left a comment
There was a problem hiding this comment.
Thanks! As usual, I only have nitpicks to offer. :)
|
@zeenix Since this PR is essentially a continuation of the implementation I did for The Safety comments (and overall implementation) I had there and here are essentially copies from the ones from the stdlib's implementation of |
Yes please. It's good to be always consistent but please in a separate PR than this.
The important bit is the logic and actual code. As long as they remain as similar as possible, I don't think deviating for improvement, is a problem.
This would be fixup of this umerged work, so I don't think so. EDIT: I might have misunderstood you here. I mean, the fixups/changes to the unmerged changes in this PR, should go in this PR. Changes to existing code (already merged) should go into a separate one. I hope it's clear now. :) |
|
Thanks for clarifying, I'll push the requested changes + submit an accompanying PR soon. |
| assert!( | ||
| tester.push_front(Droppable::new()).is_ok(), | ||
| "deque must have room for all {LEN} entries" | ||
| ); |
There was a problem hiding this comment.
Why not simply:
tester
.push_front(Droppable::new())
.expect("deque must have room for all {LEN} entries");There was a problem hiding this comment.
.expect() does not support formatting strings as it is not a macro.
Would you prefer that I use .expect(format!()), or simply not mention the LEN at all?
There was a problem hiding this comment.
I thought so too, that's why I checked before commenting: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f9cecd4084d473ebc5a41dab7b8b1c21
There was a problem hiding this comment.
I might be missing something, but your example isn't very clear/is conflicting.
It's expect()-ing the Ok(()) variant (so no error message gets printed due to a failed unwrap), and the #![allow(unused)] hides the warning that LEN is never read.
Howdy again!
I originally intended to do this after championing for the stabilization of
alloc'struncate_frontmethod, but it appears someone got to it before me!Feeling inspired, I jumped right to the
heaplessimplementation like I had done earlier last year forDeque::truncate, using the new name decided for the method in the stabilization PR.Miri seems happy, and running through the logic on pen and paper it seems sound, but please do let me know if I missed anything or if some more exhaustive tests would be needed!