10
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 03 Aug 2023
10 points (100.0% liked)
Rust Programming
9370 readers
2 users here now
founded 7 years ago
MODERATORS

Also worth mentioning, but you can early-return from a block in rust too, just using the
breakkeyword and named blocks:Edit: I haven't tried this with
asyncblocks, but I'm guessing it works there too?Flow control like return and break work differently in async blocks. They are much closer to closures than blocks in this regard. And need to be as they are lazily evaluated (like closures) and may even be evaluated well after the code that contains them has finished.
Looks like labels don't work on
asyncblocks, but using a nested inner block does work. Also, yeah,asyncblocks only exist to createFutures, they don't execute until you start polling them. I don't really see any reason why you couldn't stick a label on the async block itself though, breaking would at worst just create one new state for the future - early returned.