Static async fn in traits by tmandry · Pull Request #3185 · rust-lang/rfcs · Git...
source link: https://github.com/rust-lang/rfcs/pull/3185
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
This is an RFC to support async fn
in traits that can be called via static dispatch. These will desugar to an anonymous associated type.
I don't see anything mentioned about Send
ness. Is requiring the future to be send a potential future extension?
i suppose that requires ability to name the type of the returned future, stated in the last section of the "Future possibilities".
trait Service2 { async fn request(&self, key: i32) -> Response where Self::request::Output: Send; }
the RFC does need to state whether the default is Send
or ?Send
though. "letting the compiler automatically" is not an answer because the generic code don't know the impl.
async fn foo<S: Service>(s: &S) { let future = s.request(1); // can we assume `typeof(future): Send` or not?? future.await; }
i suppose that requires ability to name the type of the returned future, stated in the last section of the "Future possibilities".
That's right. There's a separate RFC being worked on to add this functionality and make it possible to write those bounds.
the RFC does need to state whether the default is
Send
or?Send
though. "letting the compiler automatically" is not an answer because the generic code don't know the impl.
There is no Send
default. In cases like the example you gave this is rarely a problem in practice. The reason is that we leak auto traits from async fn
(and any function with return position impl Trait). If you call foo
with a type S
where S::request::Output: Send
, the future returned by foo
will be Send
and callers are allowed to rely on this.
The story with dynamic dispatch is more complicated; there you need explicit Send
bounds. But we aren't tackling that in this RFC.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
No reviews
No one assigned
None yet
No milestone
Successfully merging this pull request may close these issues.
None yet
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK