|
|
Subscribe / Log in / New account

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

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.



to post comments

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

Posted Dec 21, 2023 16:27 UTC (Thu) by simon.d (guest, #168021) [Link]

I waited for this so long <3
Thanks to everyone making this possible!


Copyright © 2023, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds