Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::sync::Arc;
- struct Object {
- field: u32
- }
- // Will move the reference
- fn move_rc(_rc: Arc<Object>) {
- }
- fn main() {
- // Create a single Arc<T>
- let mut rc = Arc::new(Object { field: 10 });
- // Get a mutable reference
- let mut_ref = Arc::get_mut(&mut rc).unwrap();
- // Move the owner
- move_rc(rc);
- // Tell Rustc that the reference is still alive and trigger the borrow
- // checker
- println!("ref: {}", mut_ref.field);
- }
Add Comment
Please, Sign In to add comment