← Back to context

Comment by dist-epoch

8 hours ago

Sounds like the Java synchronized class.

No. It’s not a property of the type so you can have multiple items under a mutex and you’re not at the mercy of whoever wrote it, it works fine with POD types, it does not force a lock / unlock on each method call (instead the compiler essentially ensures you hold the lock before you can access the data), and the borrow checker is there to ensure you can not leak any sort of sub-states, even though you can call all sorts of helpers which have no requirement to be aware of the locking.

It’s what synchronized classes wish they had been, maybe.

Not at all. With rust you cannot accidentally leak a reference, and here's the killer: it guarantees these properties at compile time.