Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sugar is magic. I still don't know what happens behind an async and await and no tutorial really explains that to you.


https://github.com/rust-lang/async-book will be that resource, though it's not complete yet. It's important for systems languages to be able to see how stuff is implemented and reason about it, so we're committed to making it as non-magic as possible.


I disagree, magic is magic. If there's sometime done by the compiler that is impossible to do yourself in the language-- that's magic. Everything async/await is doing you could do by yourself. There's no magic in the Future trait, or any part of Rust's async solution.

You can't call it magic just because you haven't read what it desugars into. Otherwise anything you don't know could be called "magic".


Well, there's nothing you couldn't write yourself, sure... but async/await does generate unsafe code in some cases, so it is at least somewhat magical that you can do it in safe code. Since async/await has unsafe code that is really fiddly to get right otherwise (c.f. the rules for `Pin`), I think this is a pretty good tradeoff and a great use of magic.


The OP explains what's happening with the examples it provides. Was that explanation not convincing?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: