News for hackers. Stuff that matters.
Re:My favorite Rust function by Too on Sunday October 13, 2019 @02:45AM (#21238793)
Not sure how Rust mutexes work but in c++ that wouldn't work. Obvious first example is std::lock_guard which is implemented by locking in constructor and unlocking in destructor. The variable itself never has any "use", it's just created and held alive as a dummy to denote the locking scope.

Now actually this is a quite nasty object with implicit global side effects which you should avoid in the first place, but for the mutex case i don't know of a better option, maybe Rust has a better way to handle this?

Re:My favorite Rust function by kd5bjo on Sunday October 13, 2019 @03:34AM (#21239006)
Rust’s mutex guard has similar semantics, but acts as a amart pointer to the data in the mutex: if you let the guard drop, you no longer have access to the shared data.