agerasev/ringbuf

The behaviour of `Consumer::discard` as documented is currently too vague.

Closed this issue · 2 comments

The behaviour of discard is currently too vague as documented, though I suspect this is a documentation issue.

It documentation currently offers no guarantees about how many, if any, elements will be discarded. In a situation in which I know for sure that there will be no elements added to the FIFO, to adhere to the spec I still need a loop that may or may not run forever.

In my use case, in which the producer is not producing and I want to empty the fifo, it's clear from the implementation that I don't need a loop at all, and just a calling discard() with Consumer::capacity() will reliably empty the fifo.

This is a situation where a doc-test would be extremely valuable, showing in which situation it may discard less than n (i.e. when n is larger than the current number of elements or in which there is a producer race). I'm happy to contribute this if it is the desired policy for discard.

Hi, thank you for making this crate better.

I've added an information about lower bound of number of removed items (min(n, Consumer::len())) in #18. Did I understand correctly that this is what you need? If so, I'll merge the PR.

Yes, this is perfect! thanks :)