How does Rc enable shared ownership

Rc<T> enables shared ownership by tracking reference counts to free data only when all owners are dropped.

Rc enables shared ownership by wrapping a value in a reference-counted smart pointer that tracks how many owners exist. When you clone an Rc, the reference count increments; when an Rc is dropped, the count decrements, and the data is freed only when the count reaches zero.

use std::rc::Rc;

fn main() {
    let data = Rc::new(String::from("shared"));
    let clone = Rc::clone(&data);
    println!("Count: {}", Rc::strong_count(&data)); // Prints 2
}