-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Mutex::with #61974
Comments
I guess |
I wonder which cases would be made less awkward? Rust currently handles those scopes using lexical scopes and ownership. I know that the stdlib used to have quite a number of those APIs (e.g. There's a number of cases in the stdlib where scoping could be controlled using a closure, e.g. a
would make sure a file is not closed too late. FWIW: I don't think adding such a method is problematic, but given that the strategy was widespread and then removed merits a longer explanation of problematic cases/motivation. |
I think there's two rationales: First is that controlling the lifetime of Second is just a code cleanlyness/ergonomics issue. Being able to take a lock in the middle of expression-oriented code is awkward without
At one point I proposed adding |
Helper which makes taking a `Mutex` for the duration of a single closure lower friction. Issue rust-lang#61974
The associated PR ended up being closed, and for reasons that are IMO likely to require an RFC: rethinking whether poisoning locks in std is still a good idea. As such, I'm going to close this issue. |
It would be useful to have a
Mutex::with
method with the signature:This would be a convenience for quick access to a lock, especially if managing the scope of the
MutexGuard
would be awkward.cc @dtolnay
The text was updated successfully, but these errors were encountered: