liveBook · Manning

Refcell

RefCell is a Rust standard-library container that provides interior mutability by checking borrowing rules at runtime.

How 3 Manning books explain it

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.

Read how Idiomatic Rust explains refcell →

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 within shared data structures when ordinary borrowing is too restrictive.
How deep it goes
Introduces interior mutability and a linked-list implementation without detailing runtime borrow enforcement.
Examples
Uses a doubly linked list whose item references combine `Rc` and `RefCell`.
What you can do after
Apply `RefCell` with `Rc` for single-threaded shared data, and choose synchronization primitives for cross-thread use.

Read how Code Like a Pro in Rust explains refcell →

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 →

Also covered in

What to know first

Related concepts

Questions about refcell

What is refcell?

RefCell is a Rust standard-library container that provides interior mutability by checking borrowing rules at runtime.

Which Manning books explain refcell?

Idiomatic Rust, Code Like a Pro in Rust and Learn Rust in a Month of Lunches.

What should I know before learning refcell?

Manning books that teach refcell usually introduce copy, locking, atomicity and borrow checker first.

What is the difference between refcell and cell?

RefCell is a Rust standard-library container that provides interior mutability by checking borrowing rules at runtime. 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.

What is refcell a kind of?

Refcell is a kind of smart pointer. 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.