Rc<T> — reference counting, single-threaded. Arc<T> — atomic reference counting, thread-safe.
Rc<T>:
Arc<T>:
1use std::rc::Rc;2use std::sync::Arc;34// Rc: single thread5let a = Rc::new(vec![1, 2, 3]);6let b = Rc::clone(&a);78// Arc: multi-thread9let a = Arc::new(vec![1, 2, 3]);10let b = Arc::clone(&a);11std::thread::spawn(move || println!("{:?}", b));
Key: Rc for single-thread, Arc for multi-thread.