📜 async fn fundamentals Charter

This initiative is part of the wg-async-foundations vision process.

Proposal

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.

Goals

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;
  • 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.

Key outcomes

Support async drop

Users should be able to write "async fn drop" to declare that the destructor may await.

Key outcomes

  • 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 AsyncFn, AsyncFnMut, AsyncFnOnce traits.

Key outcomes

  • 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

Membership