You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
then the anonymous type implementing the Future trait automatically has a must_use annotation.
If you instead provide your own type implementing the Future trait:
then it's very easy to forget to annotate the type as must_use.
We just ran into this exact scenario where we were debugging for like an hour or so until we found the missing .await with no warning to be found by the compiler at all as it was a custom Future implementing struct.
Advantage
The compiler will warn if you forget to .await a future.
What it does
If you write an async fn:
then the anonymous type implementing the
Future
trait automatically has amust_use
annotation.If you instead provide your own type implementing the
Future
trait:then it's very easy to forget to annotate the type as
must_use
.We just ran into this exact scenario where we were debugging for like an hour or so until we found the missing
.await
with no warning to be found by the compiler at all as it was a customFuture
implementing struct.Advantage
.await
a future.Drawbacks
None
Example
Could be written as:
(Possibly with the same explanation that
async fn
gives)The text was updated successfully, but these errors were encountered: