Closed ratmice closed 1 year ago
First, I'm no maintainer here. That seems a bit special case to me.
If you drain the buffer, it means you advance the iterator. So if you had a buf_len(&self) -> usize
method (which might have a broader use case), you could then do something like it.skip(it.buf_len())
that could mimic the behavior you want, and if performance is important and if you massively peek, then maybe Multipeek
could have a specialized Iterator::nth
method (since skip
relies on it).
PS: buf_len
or any other name, a specialized nth
would internally drain needed elements.
Thanks I had indeed missed that skip
should work, if performance is a problem (which is unfortunately likely, the thing i'm implementing even specifically mentions its :fire:) I'm perhaps better off trying to cut out the buf: VeqDeque
entirely by manually incrementing indexes. As such I'll close this.
I need a way to discard peeked elements of a
MultiPeek
, it seemed the easiest way was to expose theVeqDeque
impl ofDrain
as some kind ofdrain_peeked
function. Subtracting therange.len()
from the currentbuf
index. I'm not sure if it is an elegant solution (i.e. the range of the peekbuf
differs from the range of theself
(i.e. if we implementeddrain
forMultiPeek
). In using such a drain mechanism it might also be helpful to have a function for getting thesize_hint
or aRange
for the peekbuf
rather than having to call the number of times peek has been called.Before I went and made a pull-req I was curious if you feel this warrants inclusion in itertools
MultiPeek
, or if I should just add an augmented implementation of it directly to my project -- or perhaps I missed an iterator adapter in itertools that can be used this way. Thanks.