Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. use std::sync::{Arc, Mutex};
  2.  
  3. #[derive(Debug)]
  4. struct Foo(Arc<Mutex<usize>>);
  5.  
  6. impl Foo {
  7. fn mutate(&self) {
  8. let mut current = self.0.lock().unwrap();
  9. *current = 1;
  10. }
  11. }
  12.  
  13. fn main() {
  14. let foo = Foo(Arc::new(Mutex::new(0)));
  15. println!("{:?}", foo);
  16. foo.mutate();
  17. println!("{:?}", foo);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement