Rust
02 Sep 2026
4 min read
Interior Mutability in Rust with RefCell
Rust normally enforces borrowing at compile time: either one mutable reference or any number of immutable references may exist at a given moment. That rule prevents data races and many aliasing bugs before the program runs. Sometimes the compiler cannot prove that a safe mutation pattern is valid, even though the program can enforce the rule dynamically. RefCell<T> provides interior mutability for those cases by moving borrow checking from compile time to runtime.