๐Ÿ”‘ Rust Rc and Arc

= pointer types, which allow sharing ownership of values

When to use which?

  • No threading: Rc
  • Threading: Arc

Rc

  • owned values are immutable

Example

use std::rc::Rc;

// Rust can infer all these types; written out for clarity
let s: Rc<String> = Rc::new("shirataki".to_string());
let t: Rc<String> = s.clone();
let u: Rc<String> = s.clone();

Arc