2 ms·
I've been thinking along similar lines for a little while. For me, it's not about mutation, but unrestricted mutation. When a unique reference (&mut T) exists
by Measter 5y ago
I've been thinking along similar lines for a little while. For me, it's not about mutation, but unrestricted mutation.
When a unique reference (&mut T) exists then the only possible way to even look at the data is through that unique reference. In that situation, there's no reason to have any restrictions on mutation, because nothing else can observe it.
With shared references (&T), multiple parts of the program can access the data at the same time. If you mutate in that situation you can end up with memory corruption due to data races, so mutation has to be restricted to require runtime synchronization through RefCells, Mutexs, etc.