Skip to content

Instantly share code, notes, and snippets.

@baakeydow
Created October 18, 2022 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baakeydow/ec2c0f97b1270c1cbb1c1433e052f1bc to your computer and use it in GitHub Desktop.
Save baakeydow/ec2c0f97b1270c1cbb1c1433e052f1bc to your computer and use it in GitHub Desktop.
#rust multiple owners with Rc + RefCell
fn multiple_owners() {
use std::rc::Rc;
use std::cell::RefCell;
let value = Rc::new(RefCell::new(5));
let a = Rc::clone(&value);
let b = Rc::clone(&value);
*a.borrow_mut() += 1;
*b.borrow_mut() += 1;
assert_eq!(*value.borrow(), 7);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment