ownership
Rust Rc<RefCell<T>>
Combine shared ownership and runtime-checked mutation in a single thread. Cloning the Rc shares the same cell; each owner observes updates after a writer guard is released. This is different from cloning a payload. Expected output (not executed): ["draft", "review"] Why: Both handles own the same cell. Common mistake: Replacing Rc with Arc and assuming RefCell becomes thread-safe.
Formal Syntax & Structure
rust syntaxrust
Rc::new(RefCell::new(value))Working Example
Example Snippetrust
use std::{cell::RefCell, rc::Rc};fn main() { let tasks = Rc::new(RefCell::new(vec!["draft"])); let editor = Rc::clone(&tasks); editor.borrow_mut().push("review"); println!("{:?}", *tasks.borrow());}