What would be a way for me to write a panic-safe mecanism in Rust that behaves similarly to Java's try { ... } finally { ... }, where the try and finally blocks each mutably borrow the same value?
What I need is for a try block's borrows to finish as soon as control leaves it, whether by normal execution or panic unwinding, with the finally block borrowing only once control reaches it.
With scopeguard::defer!, the closure has to be declared before the equivalent try block, which starts the mutable borrow immediately upon creating that closure, which means the code corresponding to the try block cannot then take its own mutable borrow of the same thing already borrowed by that closure.