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.
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.
Replies (1)
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.