📜 async fn fundamentals Charter
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.
Able to write
async fn in traits and trait impls
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;
dynvalues, 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 fnmust still be dyn safe though some tuning may be required
- Return futures must easily be bound by
Support async drop
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
Support async closures and
- Async closures work like ordinary closures but can await values
- Traits analogous to
FnOnceexist for async
- Reconcile async blocks and async closures