RefCell<T>
In this lesson, you will learn about RefCell<T>.
What is RefCell<T>
RefCell<T>
is also a shareable mutable container like Cell<T>
. The compiler enforces the rules of references for CellRefCell<T>
gives us flexibility with dynamic rule checking, meaning borrows are tracked during runtime.
How dynamic borrow checking works?
To understand this, Let’s have a look at RefCell<T>
definition in the standard library,
pub struct RefCell<T: ?Sized> {
borrow: Cell<BorrowFlag>,
// Stores the location of the earliest currently active borrow.
// This gets updated whenever we go from having zero borrows
// to having a single borrow. When a borrow
...Access this course and 1400+ top-rated courses and projects.