Refcell
RefCell is a Rust standard-library container that provides interior mutability by checking borrowing rules at runtime.
Idiomatic Rust
RefCell is Rust's single-threaded interior-mutability container that checks borrowing rules at runtime.
- How it is used
- Enables mutation of owned data inside an immutable container when ordinary mutable access is unavailable.
- How deep it goes
- Explains runtime-enforced interior mutability and demonstrates borrow_mut(), without detailing borrow-conflict behavior.
- Examples
- Moves an immutable String into RefCell, calls borrow_mut().push_str(...), and displays the changed value.
- What you can do after
- Apply it via RefCell::from and borrow_mut() to mutate an owned String without a mutable container binding.
Code Like a Pro in Rust
RefCell is a Rust standard-library type that provides runtime-checked borrowing and interior mutability for single-threaded code.
- How it is used
- Enables mutable access inside shared, single-threaded data structures when ordinary mutable references are too restrictive.
- How deep it goes
- Explains when to use RefCell and shows its placement in a list; defers concurrency and does not detail runtime borrow checks.
- Examples
- Uses a doubly linked list whose node references have the type `Rc<RefCell<ListItem<T>>>`.
- What you can do after
- Apply it via Rust’s `RefCell` and `Rc` to structure mutable, shared nodes in a single-threaded list.
Learn Rust in a Month of Lunches
RefCell is a Rust standard-library container that enforces borrowing rules at run time and permits mutation through an immutable access path.
- How it is used
- Enables selected fields to change through immutable access paths when ordinary mutable references are inconvenient.
- How deep it goes
- Explains initialization, borrowing methods, runtime panics, error-returning alternatives, and thread restrictions.
- Examples
- Uses a User with an active RefCell<bool>, direct mutation, double mutable borrowing, and the resulting panic.
- What you can do after
- Apply it via RefCell::new, borrow, borrow_mut, and try_borrow_mut while avoiding invalid simultaneous borrows.
Read how Learn Rust in a Month of Lunches explains refcell →
Related concepts
- interior mutabilityuses · Interior mutability is a programming mechanism that permits mutation through an otherwise shared or immutable access path while enforcing safety through specialized checks or synchronization.
- mutexused by · A mutex is a synchronization primitive that provides controlled exclusive access to shared data or another resource.
- cellcontrasts with · Cell is a Rust standard-library type that provides interior mutability by allowing values to be retrieved or replaced through shared access without exposing references to its contents.
- smart pointerkind of · A smart pointer is a pointer-like object that manages or mediates access to a referenced resource, often providing ownership, lifetime, or safety behavior.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


