Enables Interior Mutability for any type, enforces Borrowing Rules at Runtime instead of Compile time.

let r = RefCell::new(vec![1, 2]);
r.borrow();     // &Vec - panics if already mutably borrowed
r.borrow_mut(); // &mut Vec - panics if already borrowed
  • Works with any T
  • Can panic at runtime if rules are violated

Typical use: combined with Rc for shared mutable state in single-threaded code:

Rc<RefCell<Vec<T>>>