What is the point of using cell since mutable reference can be obtained using Rc::get_mut?

Rc is doing reference counting, so there is overhead for storing the count, reading it, and modifying it. Raw pointers won't have that problem. RefCell has to keep track if the data is already being borrowed, so there's some overhead in checking that. (For instance, if there is a borrow, the attempt will panic, so the code has to do a conditional branch.) I don't think there's any overhead for Cell (I never wanted to use it), but it only works on copy types.

Raw pointers will outperform most of this, but you lose the safety of having ownership and borrowing modeled in the type system, which means you have to be careful to avoid the pitfalls of managing memory manually and racy data accesses and whatnot.

Also, Rc<Box<T>> is redundant, because Rc already does everything that Box does.

2 Likes