Ben Chuanlong Du's Blog

It is never too late to learn.

Cell and RefCell in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

https://doc.rust-lang.org/std/cell/

https://doc.rust-lang.org/std/cell/struct.RefCell.html

Rust Cell and RefCell

Rc + RefCell is another alternative to circumvent Rust's borrow checker at compile time. Checks at runtime and might might panic if there are borrowing issues in your code.

comes at a performance penalty as it is slower to track borrowing at runtime.

  1. Avoid use Cell and RefCell unless you have to rely on them to circumvent Rust's borrow checker at compile time.

References

Comments