Guest User

Untitled

a guest
Mar 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. use std::rc::Rc;
  2. use std::cell::Cell;
  3.  
  4. #[derive(Debug)]
  5. struct NonCopyBool(bool);
  6.  
  7. fn main() {
  8. let flag = Rc::new(Cell::new(NonCopyBool(false)));
  9.  
  10. let clone = flag.clone();
  11. let otherclone = flag.clone();
  12.  
  13. let c1 = move || {
  14. *(*clone).get_mut() = NonCopyBool(true);
  15. };
  16.  
  17. let c2 = move || println!("{:?}", otherclone.replace(NonCopyBool(false)));
  18.  
  19. c1();
  20. c2();
  21. }
  22.  
  23. /*
  24.  
  25. fn main() {
  26. let mut flag = NonCopyBool(false);
  27.  
  28. let mut ptr = &mut flag as *mut NonCopyBool;
  29.  
  30. let mut c1 = || { unsafe { *ptr = NonCopyBool(true)} };
  31.  
  32. let mut c2 = || {println!("{:?}", flag);};
  33.  
  34. c1();
  35. c2();
  36.  
  37. }
  38. */
Add Comment
Please, Sign In to add comment