Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using an async block or function in a trait #82

Closed
seanmonstar opened this issue Mar 22, 2021 · 0 comments · Fixed by #134
Closed

Using an async block or function in a trait #82

seanmonstar opened this issue Mar 22, 2021 · 0 comments · Fixed by #134
Labels
good first issue Good for newcomers help wanted Extra attention is needed status-quo-story-ideas "Status quo" user story ideas

Comments

@seanmonstar
Copy link
Contributor

Brief summary

It's very easy to write inherent async fns on a type, but if using them inside a trait method is much harder. For example, this pseudo code doesn't work, and making it work isn't intuitive:

impl Service for Handler {
    type Future = WhatTypeGoesHere;
    fn call(&self, req: Request) -> Self::Future {
        async move {
            self.count(req).await;
            Ok(self.construct_response())
        }
    }
}

Optional details

  • (Optional) Which character(s) would be the best fit and why?
    • Any of the characters, since it's hard in general. Barbara may know how to work around it, but she likely still doesn't like it.
  • (Optional) What are the key points or morals to emphasize?
    • It's confusing that you can't write async fn when implementing a trait.
    • It's hard to return a future from a trait method that came from another async fn or async block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed status-quo-story-ideas "Status quo" user story ideas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant