Open yanns opened 4 months ago
Hi, apologies for not responding on this.
Yes, currently, the implementation only works for 'static
items returned from the futures. I may be wrong, but I think it's not possible to convince the type-system about the life-time of the output of the future itself, without boxing it. But boxing it defeats the purpose of returning the refs in the first-place itself.
Thanks for the answer!
I may be wrong, but I think it's not possible to convince the type-system about the life-time of the output of the future itself, without boxing it
Do you think that join_all
have found a solution for the type system, or are they using boxing, or are they using another solution?
No, the issue stems from a std::mem::transmute
trick that crates like ours use (other being crossbeam::threads): change the lifetime to 'static
. This step is not reqd. in join_all
.
Now, the design of this crate where Scope
is generic over T
doesn't make it easy to express the static version of T, so instead we need T: 'static
. Similarily, even the future type F
is generic, so indeed, we do an extra box-ing of the future to be able to name the output type.
Thanks for the explanation!
I let you choose if you want to keep this ticket open for future work, and if you want to close it as you don't plan to do it.
when using
join_all
, we can use references in function results, like:When trying to use
scope_and_collect
instead, this does not compile: