std-type

Rust Rc<T>

Rc shares ownership of one payload within a thread. Each owning handle contributes to the lifetime of the value. Dropping one handle does not destroy the payload while another remains. Rc does not implement Send or Sync. Expected output (not executed): Lunch Why: The kitchen handle remains an owner after menu is dropped. Common mistake: Assuming Rc automatically allows mutation through a shared handle.

Formal Syntax & Structure

rust syntaxrust
Rc::new(value)

Working Example

Example Snippetrust
use std::rc::Rc;fn main() {    let menu = Rc::new(String::from("Lunch"));    let kitchen = Rc::clone(&menu);    drop(menu);    println!("{kitchen}");}
Rust Reference