Guest User

Untitled

a guest
Sep 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. use std::sync::Arc;
  2.  
  3. struct Object {
  4. field: u32
  5. }
  6.  
  7. // Will move the reference
  8. fn move_rc(_rc: Arc<Object>) {
  9.  
  10. }
  11.  
  12. fn main() {
  13. // Create a single Arc<T>
  14. let mut rc = Arc::new(Object { field: 10 });
  15.  
  16. // Get a mutable reference
  17. let mut_ref = Arc::get_mut(&mut rc).unwrap();
  18.  
  19. // Move the owner
  20. move_rc(rc);
  21.  
  22. // Tell Rustc that the reference is still alive and trigger the borrow
  23. // checker
  24. println!("ref: {}", mut_ref.field);
  25.  
  26. }
Add Comment
Please, Sign In to add comment