Announcing `async fn` and return-position `impl Trait` in traits (Rust Blog)

Post Syndicated from corbet original https://lwn.net/Articles/955925/

The Rust Blog announces
the stabilization of a couple of trait features aimed at improving support
for async code:

Ever since the stabilization of RFC #1522 in Rust 1.26, Rust has
allowed users to write impl Trait as the return type of
functions (often called “RPIT”). This means that the function
returns “some type that implements Trait“. This is
commonly used to return closures, iterators, and other types that
are complex or impossible to write explicitly. […]

Starting in Rust 1.75, you can use return-position impl
Trait
in trait (RPITIT) definitions and in trait impls. For
example, you could use this to write a trait method that returns an
iterator: […]

So what does all of this have to do with async functions? Well,
async functions are “just sugar” for functions that return
-> impl Future. Since these are now permitted in
traits, we also permit you to write traits that use async fn.