Wonder if allowing to cancel existing SendRef would be possible? E.g. something along the lines of
impl<'a, ...> SendRef<'a, ...> {
/// Drops this send ref *without* sending the data. The slot is returned to the pool.
pub fn cancel(self) {
...
}
}
Here's a particular sample use case:
- We're reading network messages from multiple threads into a single thingbuf, trying to avoid all allocations and copying if possible (and recycling really helps with that).
- Reading those messages is a complicated process - they don't arrive as
&[u8] but have to be combined and processed in a streaming fashion, so each message is a BufRead reader.
- In order to avoid copying, we reserve a
SendRef slot and .read_to_end() directly into it.
- However, sometimes it turns out that those messages have to be filtered out and should never reach the thingbuf receiver...
- ... but alas, it's too late. As soon as
SendRef is dropped, it will be sent away.
- We can either use some hacky convention like sending empty messages, or some enums, or maybe do reading into a separate buffer first - all of these will work as workarounds, but the cleanest way would be to able to
send_ref.cancel() which would cancel the reservation and return the slot to the pool - hence this question.
Thanks!
Wonder if allowing to cancel existing
SendRefwould be possible? E.g. something along the lines ofHere's a particular sample use case:
&[u8]but have to be combined and processed in a streaming fashion, so each message is aBufReadreader.SendRefslot and.read_to_end()directly into it.SendRefis dropped, it will be sent away.send_ref.cancel()which would cancel the reservation and return the slot to the pool - hence this question.Thanks!