4 ms·
Yes, you can encode state machines manually, but it will be FAR less ergonomic than the async syntax. Rust has started with a library-based approach, but it was
by newpavlov 6y ago
Yes, you can encode state machines manually, but it will be FAR less ergonomic than the async syntax. Rust has started with a library-based approach, but it was... not great. Async code was littered with and_then methods and it was really close to the infamous JS callback hell. The ergonomic improvements which async/await brings is essentially a raison d'être for incorporating this functionality into the language.
- eru 6y agoInteresting! For comparison, Haskell went with the library approach but has the syntactic sugar of the equivalent of `and_then` built into the language. (I am talking about Monads and do-notation.) It's a bit like iterating in Python: for-loops are a convenient syntactic sugar to something that can be provided by a library.
- newpavlov 6y agoYes, a number of people have suggested introduction of a general do notation (or its analog) instead of usecase-specific async/awayt syntax, but since Rust does not have proper higher kinded types (and some Rust developers say it never will), such proposals have been deemed impractical.
- pdpi 6y agoIt’s not just HKTs. Figuring out how to handle Fn, FnOnce, FnMut is a whole other can of worms.
- smt1 6y agoI think there were some (related, I think!) proposals here: https://github.com/rust-lang/lang-team/issues/23 https://github.com/rust-lang/lang-team/issues/23 https://github.com/rust-lang/rfcs/issues/3000 https://github.com/rust-lang/rfcs/issues/3000
- steveklabnik 6y agoIt is a little old, but for the general gist of it, http://aturon.github.io/tech/2018/04/24/async-borrowing/ http://aturon.github.io/tech/2018/04/24/async-borrowing/ is an amazing description of the problem here. It is a PhD level research problem to know if monads and do notation would be able to work in Rust. The people who are most qualified to look into it (incidentally: a lot of the same crew was who was working on async) believe that it may literally be impossible.
- anp 6y agoMy impression is that some of them even burnt out in slog of a supposedly rushed process to land async/await!
- deleted 6y ago[deleted]
- shmerl 6y agoCan't Rust come up with a new syntax (that matches io_uring idea better) and deprecate the old one? Or simply replace the implementation keeping the old syntax if it's semantically the same?
- kibwen 6y agoIt could, although I highly doubt that any deficiencies with the current implementation of async/await are so severe as to warrant anything so dramatic.