Rc<T>
In this lesson, you will learn about `Rc<T>`.
What is Rc
Rc
stands for Reference Counted
. Rc
does not allow shared mutation like how RefCell
and Cell
do. When all Rc
pointers are destroyed then the inner value T
is also destroyed. Rc
can be used only for single-threaded applications just like RefCell
and Cell
.
Why do we need to Rc<T>
?
You will see Rc
often being used with data structures that require a lot of pointers involving cycles. When you are doing an operation on the heap, you will depend on multiple owners and you will not know for sure which owner will live longer than the other this is where Rc
comes into use. Rust will deallocate the heap data once all Rc
...
Access this course and 1400+ top-rated courses and projects.