This initiative is part of the wg-async-foundations vision process.
async fn
exists today, but does not integrate well with many core language features like traits, closures, and destructors. We would like to make it so that you can write async code just like any other Rust code.
The goal in general is that async fn
can be used in traits as widely as possible:
- for foundational traits, like reading, writing, and iteration;
- for async closures;
- for async drop, which is built in to the language;
- in
dyn
values, which introduce some particular complications; - in libraries, for all the usual reasons one uses traits;
- in ordinary programs, using all manner of executors.
- Async functions in traits desugar to impl Trait in traits
- Traits that use
async fn
must still be dyn safe though some tuning may be required - Return futures must easily be bound by
Send
Users should be able to write "async fn drop" to declare that the destructor may await.
- Types can perform async operations on cleanup, like closing database connections
- There's a way to detect and handle async drop types that are dropped synchronously
- Await points that result from async cleanup can be identified, if needed
Support async closures and AsyncFn
, AsyncFnMut
, AsyncFnOnce
traits.
- Async closures work like ordinary closures but can await values
- Traits analogous to
Fn
,FnMut
,FnOnce
exist for async - Reconcile async blocks and async closures
Role | Github |
---|---|
Owner | tmandry |
Liaison | nikomatsakis |