MacMusic  |  PcMusic  |  440 Software  |  440 Forums  |  440TV  |  Zicos
trait
Recherche

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

jeudi 21 décembre 2023, 17:02 , par LWN.net
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.
https://lwn.net/Articles/955925/

Voir aussi

News copyright owned by their original publishers | Copyright © 2004 - 2024 Zicos / 440Network
Date Actuelle
jeu. 2 mai - 22:14 CEST