Feature request: Allow non-Send broadcast values in more (generic) contexts #6902
Labels
A-tokio-stream
Area: The tokio-stream crate
A-tokio-util
Area: The tokio-util crate
C-feature-request
Category: A feature request.
Is your feature request related to a problem? Please describe.
In my library
eyeball-im
, I usetokio_util::sync::ReusableBoxFuture
to implement aStream
on top of atokio::sync::broadcast
channel. This is the same thingtokio_stream::wrappers::BroadcastStream
does. However, this means that the messages being sent over the channel must beSend
. I can also box the future myself without requiringSend
ness of the message type, but then my own receive futures become non-Send
.Describe the solution you'd like
I would like to avoid boxing to let the compiler infer
Send
-ness of the involves futures. Iftokio::sync::broadcast::Receiver::recv
returned a named future,tokio_stream::wrappers::BroadcastStream
could drop theSend
bound onT
, and I could drop the same bound in my library too.Describe alternatives you've considered
I have a PR with a copy-pasted
ReusableBoxFuture
without theSend
bounds, and a wrapper type for it that is only ever instantiated with the same (unnameable) future that invokesreceiver.recv()
and that I know isSend
if the message type is. There's a static assertion thatT: Send
-><unnameable future>: Send
, andunsafe
ly implementedSend
for the wrapper type: jplatte/eyeball@e4fd1f5#diff-5a8e4292bd84885e0f16976040ee79e231ab74df5283d52565cd4fec4ab92d75R271-R292However, it seems wrong to require
unsafe
for this. My code's soundness is probably relying on tokio not doing weird things with theSend
-ness of thebroadcast::Receiver::recv
future.. not a huge deal but it doesn't feel good to releaseunsafe
code with no serious attempt at a soundness proof.The text was updated successfully, but these errors were encountered: