An unofficial, read-only Hacker News reader. Join the beta →

2035 came early (opens external site)

1036 points by setheron 4 days ago | fzakaria.com | 382 comments on HN

View full thread · View on Hacker News

Comment thread (2)

  1. I think your parent is thinking of the thread::scoped API, which was removed before Rust 1.0, and is back now. And it illustrates a technique to do what it is that you want, even if you can’t literally do what you want, but there’s sort of a parallel to defer vs RAII, in that it doesn’t really let you fully escape the parent scope, but does give you what you want in certain circumstances.
    Replies (1)
    1. Right, if your use case works with thread::scope (as I mentioned) you can get it working.

      The thread::scope is kind of a workaround that may or may not work for your use case and I trust people are able to figure out that I’m illustrating a limitation, and not asking “how can I get this code to work”.

      If lifetimes could be bounded from above, then we could say that references which the closure borrows are bounded above by the scope containing the thread. We can’t do this, so we use thread::scope instead, which introduces a second closure just to work around the limitation.