&, &mut, shared_ref, unique_ref

Is it correct to think of:

& as shared_ref
&mut as unique_ref

and we can write to something if and only if the entire "access chan" is all unique_ref and no shared_ref ?

If not, what is a counter example of where this breaks down ?

Yes, assuming no further meaning that you're pulling from somewhere else like another language.

It breaks down in the face of shared mutability, aka interior mutability.

And pedantically in the face of ownership, since you don't need a &mut String to overwrite a String you own, say.


Good call. Besides ownership & Cell/RefCell/Mutex/RWLock, are there any other exceptions?

I wrote a short article about this a few years ago:



Atomics, OnceCell, anything else utilizing UnsafeCell.

You can write through raw pointers like a *mut T too (unsafely).

1 Like