Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::rc::Rc;
- use std::cell::RefCell;
- #[derive(Debug)]
- struct NonCopyBool(bool);
- fn main() {
- let flag = Rc::new(RefCell::new(NonCopyBool(false)));
- let clone = flag.clone();
- let otherclone = flag.clone();
- let c1 = move || {
- *clone.borrow_mut() = NonCopyBool(true);
- };
- let c2 = move || println!("{:?}", *otherclone.borrow());
- c1();
- c2();
- }
- /*
- fn main() {
- let mut flag = NonCopyBool(false);
- let mut ptr = &mut flag as *mut NonCopyBool;
- let mut c1 = || { unsafe { *ptr = NonCopyBool(true)} };
- let mut c2 = || {println!("{:?}", flag);};
- c1();
- c2();
- }
- */
Add Comment
Please, Sign In to add comment