Currently, the SendRef and RecvRef types returned by thingbuf::mpsc's senders and receivers contain a borrowed reference to the channel's queue. This means that a Ref from a channel cannot live for the 'static lifetime. However, because the channel's queue is either internally reference counted (in the case of the dynamically allocated MPSCs) or lives in a static variable (in the case of the static MPSCs), it should also be possible to create a reference to a queue slot that is 'static.
We could add an API like tokio::sync::mpsc's Sender::reserve_owned, which clones the internal Arc around the channel's shared data and returns a permit whose lifetime is not bound to a borrow of the Sender handle that produced it.
This could potentially enable some neat stuff, like using a thingbuf mpsc::Receiver of Vec<u8>s as a http_body::Body without having to copy data out of the thingbuf --- in this case, an OwnedRecvRef type could be passed directly into hyper or another HTTP library, and when the library finishes sending the body chunk, that ref is dropped, returning the buffer to the pool.
Currently, the
SendRef
andRecvRef
types returned bythingbuf::mpsc
's senders and receivers contain a borrowed reference to the channel's queue. This means that aRef
from a channel cannot live for the'static
lifetime. However, because the channel's queue is either internally reference counted (in the case of the dynamically allocated MPSCs) or lives in astatic
variable (in the case of the static MPSCs), it should also be possible to create a reference to a queue slot that is'static
.We could add an API like
tokio::sync::mpsc
'sSender::reserve_owned
, which clones the internalArc
around the channel's shared data and returns a permit whose lifetime is not bound to a borrow of theSender
handle that produced it.This could potentially enable some neat stuff, like using a thingbuf
mpsc::Receiver
ofVec<u8>
s as ahttp_body::Body
without having to copy data out of thethingbuf
--- in this case, anOwnedRecvRef
type could be passed directly intohyper
or another HTTP library, and when the library finishes sending the body chunk, that ref is dropped, returning the buffer to the pool.