3 ms·
Rust can have mixed mutability - see Interior Mutability (Cell/RefCell/Atomic/Mutex). But in Rust the distinction is actually about shared vs exclusive access.
by pornel 6y ago
Rust can have mixed mutability - see Interior Mutability (Cell/RefCell/Atomic/Mutex).
But in Rust the distinction is actually about shared vs exclusive access. This is the aspect that really matters for safety. Access is properly of the code, not data, so it can be dynamic from data's perspective (the same data can be borrowed exclusively or not at different times)
When you have exclusive access, immutability becomes irrelevant, because nobody else can observe the mutation (so e.g. exclusive reference to a Mutex can skip locking!)