async_futures.txt (624B)
1 # Coroutines and async/await 2 3 These two signatures are functionally equivalent — `async fn` is just syntactic 4 sugar that the compiler desugars into the explicit `impl Future` form. 5 6 ```rust 7 trait T { 8 async fn f(&self) -> u32; 9 } 10 ``` 11 12 ```rust 13 trait T { 14 fn f(&self) -> impl Future<Output = u32>; 15 } 16 ``` 17 18 Similar to how JavaScript rewrites an await function into a normal function with 19 promises, when you write this in Rust: 20 21 ```rust 22 async fn run() -> () {...} 23 ``` 24 25 It becomes: 26 27 ```rust 28 Fn run() -> impl Future<Ouput = ()> 29 ``` 30 31 The Rust futures we use today have a lot in common with how `async/await` works 32 in JavaScript.