Guest User

Untitled

a guest
Mar 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 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 || clone.set(NonCopyBool(true));
  14.  
  15. let c2 = move || println!("{:?}", otherclone.replace(NonCopyBool(false)));
  16.  
  17. c1();
  18. c2();
  19. }
  20.  
  21. /*
  22.  
  23. fn main() {
  24. let mut flag = NonCopyBool(false);
  25.  
  26. let mut ptr = &mut flag as *mut NonCopyBool;
  27.  
  28. let mut c1 = || { unsafe { *ptr = NonCopyBool(true)} };
  29.  
  30. let mut c2 = || {println!("{:?}", flag);};
  31.  
  32. c1();
  33. c2();
  34.  
  35. }
  36. */
Add Comment
Please, Sign In to add comment