Rc::new, Rc::clone, Rc::strong_count
pub fn new(value: T) -> Rc<T>
pub fn clone(this: &Rc<T>) -> Rc<T>
pub fn strong_count(this: &Rc<T>) -> usizeShare ownership of T on one thread. Cloning an Rc does not clone T, and the type cannot be sent to another thread.
| Parameter | Description |
|---|---|
value / this | The owned value, or an existing Rc to clone. clone shares the allocation. |
Returns: A new Rc handle. strong_count is the number of strong handles still alive.
- This example stays on the main thread because Rc is not Send. Crossing threads is a compile error, not something this binary can demonstrate by running.
use std::rc::Rc;
fn main() {
let first = Rc::new(5);
let second = Rc::clone(&first);
println!("{} {}", Rc::strong_count(&first), *second);
}Expected output
2 5Related: Arc and Mutex