-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conflict with mutable/immutable borrows #22
Comments
defer is using a closure, you can use a macro less version of that to see it better - but it has the borrow checker errors as any closure would have. The version of the scope guard that takes and owns a value exists to solve this problem (see examples in docs). |
Hey, thanks for the response. Based on the example in the docs, I made it to here:
However, I think this situation is more complex than what you show in the doc, because the value being mutated is outside the scope that I want to exit on, so I'm getting a bunch of value moved on previous iteration type issues. It seems pretty clear that the complexity required here isn't worth it, but as a purely academic exercise, I'd be delighted to figure out how to make this work. Here's a playground link if you're interested to experiment: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c4407108eabe72ab21604d7c09d43159 |
The academic solution is scopeguard::guard(&mut preamble Innovations welcome, in this crate or elsewhere 🙂 |
Hey, thanks for the nifty package! I'm a newer rustacean just getting my feet wet doing advent of code, and today's puzzle had a situation where I wanted to defer some processing until the scope exited:
I totally appreciate that the VecDeque is overkill here and just using a sliding slice would have more than done the job, but I'm curious about why I have trouble compiling this:
When I just paste the code in at the two possible exit points, it accepts it fine, so I'm having trouble understanding what the issue is here with defer's internal closure. Is there some way to resolve this or is it intractable?
The text was updated successfully, but these errors were encountered: