Some types allow you to mutate values through a shared reference with a mechanism called interior mutability.
There can be two categories:

  • types like Mutex or RefCell which ensure that only one mutable reference and no shared references exist at the same time
  • types that do not give out a mutable reference to the inner value, but give methods to manipulate the value in place. Examples include the atomic integer types and std::cell::Cell

See Reference Types and Interior Mutability > Interior mutability for a complete list and comparison.

See also

References

  • J. Gjengset, Rust for Rustaceans: Idiomatic Programming for Experienced Developers. No Starch Press, 2021.