2 ms·
In safe Rust, all mutation must be either: - Statically verified to be unique (&mut) - Dynamically verified to be unique (RefCell) - Behind a lock (Mutex, Rw
by Nullabillity 6y ago
In safe Rust, all mutation must be either:
- Statically verified to be unique (&mut)
- Dynamically verified to be unique (RefCell)
- Behind a lock (Mutex, RwLock)
- Explicitly opt into weaker (but still consistent) guarantees (atomics)
- Some other abstraction built on those primitives (like channels)
Unsafe does exist, but it's something that the code must explicitly opt into, and they rules that must be followed are generally "the same" across the whole Rust ecosystem (rather than just accidentally stumbling into something that is OK in "normal" Scala but breaks some weird Akka rule).
In any case, the language enforces that you are self-consistent: if you use locks as your escape hatch for something then the code won't compile if you try to access it without an active lock.