-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
It is hard to see the return types of async functions #69781
Comments
IMO a function returning a future being implemented via |
Why would I care as a consumer of the API if the function is implemented using |
One idea is to leave the output as-is, but add an async "badge" next to any function which returns And maybe you could click/hover over the badge to see the desugared signature of |
I just think it is important that it stands out more. I would prefer if it is clearly visible on the right side because that is where the return type is. But first I guess we should decide if this is something we want to solve at all. Maybe nobody else has this problem. Functions implemented with returning Futures are not a problem, you see immediately that they return a future by looking at their return type. The problem isn't figuring out if it is async. This I could do by looking at the async keyword. The problem is that I'm fooling myself that the function returns something other than a Future because that is what it looks like. So the solution has to stand out so much so that I don't mistake the function for a non-async function. I'm not really convinced by hover-effects. I don't hover every line I read. |
I really believe the most sane and obvious answer is to remove the
|
I would like to see this as well: show the real return type, and optionally add an |
How would this apply to |
the function you link to returns a boxed pin. if all async functions does that I've completely misunderstood what a async desugares to. then it is even more important that the real type is in the signature. |
My belief is that once you understand that an |
There are probably many reasonable ways to document async functions. The best IMO is to list the real types by default, |
One thing @Nemo157 mentioned is that there is a difference between That said this does seem useful. Maybe it could be opt-in, with |
I think #63037 would help with this (and could be done automatically, it's just a bug fix in rustdoc). |
This isn't really feasible, rustdoc runs after macro expansion: #1998 |
Rewriting an I think adding a toggle button might be a good solution. |
I agree with the premise but would rephrase it as identifying asynchronous functions is unnecessarily complex. However, I wouldn't automatically assume that drilling into the details of the return type, and exposing them, is what the users want and need. There are three ways to declare an "asynchronous function" that I know of: async fn foo() { } // keyword
fn bar() -> impl Future<..> { .. } // impl
fn baz() -> SomeCustomFut { .. } // custom Whichever style is more frequent in the user's projects might influence their way of identifying asynchronous functions. Hence, I'm hesitant to giving special status to one syntax and claiming it's "less confusing". I think the declaration should reflect the way the code was written, just like it is in other cases. A badge for any type that implements Hovering does not work on touch screens. Clicking for more info sounds a bit undiscoverable, but yeah perhaps. In either case, an interactive solution requires a default, which still puts us in a value-judgment position of choosing the "least confusing" option. I don't think this is necessary to solve OPs problem. |
In the documentation it is hard to distinguish async functions from normal functions.
Take for example warp::Server. Both
run
andbind
returns futures. But when I was reading the docs I thought onlybind
was asynchronous. And I had a lot of problems getting my code to work due to wrong assumptions about the types...My suggestion is that async functions are listed in a separate listing, have another color, use the correct return type (Future) or in some other way stand out.
ref: https://www.reddit.com/r/rust/comments/fef3zh/minor_rant_about_async_syntax_and_documentation/
The text was updated successfully, but these errors were encountered: