As a Go programmer, I find it quite puzzling that Rust didn't handle panic edge cases as well as Go did with defer keyword. Defer executes at the end of a function, regardless of whether it returned or panic'd, so you can write safe mutex code just by doing something like:
mutex.Lock()
defer mutex.Unlock()
And if you need to unlock the mutex in one of multiple places, you can wrap it into a sync.Once.
There must be a reason Rust doesn't do something similar...
Editions can definitely be made to alter standard library APIs in principle, thought the machinery for that probably needs to be developed a bit. But that's why I qualified my proposal with "if a breaking change is going to happen".
3 comments
[ 0.54 ms ] story [ 604 ms ] threadThere must be a reason Rust doesn't do something similar...