Post

In Rust, a &T is not an immutable reference in the common Functional Programming sense. func(&self) is free to mutate atomics or values wrapped in Mutex through self because any other call through an alias to self is going to synchronize the mutations. &T means "you can have other aliases".

&mut T means "you cannot have other aliases". This contrasts with C++ const where aliases are all over the place and const only exists to help you be suspicious about side-effects.

0 reposts2 likes

A method that takes a lock and performs some mutation would be non-const in C++. But if you were to declare it as `&mut self` in Rust, you would not be able to have concurrent callers. The whole point of having a Mutex in the first place!