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
SendRefandRecvReftypes returned bythingbuf::mpsc's senders and receivers contain a borrowed reference to the channel's queue. This means that aReffrom a channel cannot live for the'staticlifetime. However, because the channel's queue is either internally reference counted (in the case of the dynamically allocated MPSCs) or lives in astaticvariable (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 internalArcaround the channel's shared data and returns a permit whose lifetime is not bound to a borrow of theSenderhandle that produced it.This could potentially enable some neat stuff, like using a thingbuf
mpsc::ReceiverofVec<u8>s as ahttp_body::Bodywithout having to copy data out of thethingbuf--- in this case, anOwnedRecvReftype could be passed directly intohyperor another HTTP library, and when the library finishes sending the body chunk, that ref is dropped, returning the buffer to the pool.