3 ms·
Ohhh.... I think I get it. The root of my confusion is that BRACES ARE OPTIONAL in Rust closures. This is apparently valid Rust: let func = || println!("foo!"
by api 6y ago
Ohhh.... I think I get it. The root of my confusion is that BRACES ARE OPTIONAL in Rust closures.
This is apparently valid Rust:
let func = || println!("foo!");
I didn't know that, which is why I thought "|| async move ..." was some weird form of pseudo-async-closure instead of what it is: a function that returns an async function.
Most of the code I see always uses braces in closures for clarity, but I now see that a lot of async code does not.
- leshow 6y ago> I didn't know that, which is why I thought "|| async move ..." was some weird form of pseudo-async-closure instead of what it is: a function that returns an async function. It does not return an async function, it is a closure that returns a future. Carefully read the function signature I had posted: fn foo<F, Fut>(f: F) where F: Fn() -> Fut, Fut: Future async move {} is just a future, there is no function call. || is a closure, put them both together and you have a closure that returns a future. edit: I'm trying to think of how else to explain this. a future is just a state machine, an expression, there is no function call. let f = async move { }; Is a valid future, you can f.await just fine.