Open jplatte opened 3 weeks ago
@Darksonn I see you added some labels. Is this feature request is "accepted" then, i.e. a PR for this would be welcome?
I don't know if adding labels necessarily means that, but yes I would be okay with a PR for this. Sorry for not responding earlier. I think we can perhaps add an unsafe method to ReusableBoxFuture
that takes a Future
without a 'static
or Send
bound, and then it's up to the caller to make sure that they don't use the future in violation of its true trait bounds.
I don't know if adding labels necessarily means that
Yeah I don't think it does, but it means you looked at and understood the request, so I felt like nothing more was going to happen until I explicitly asked :)
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: https://github.com/jplatte/eyeball/pull/63/commits/e4fd1f59bf4bf283e0c8d413e73316169ef20d9f#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.