Transaction deployment

⚓ Rust    📅 2025-11-08    👤 surdeus    👁️ 3      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Transaction deployment
#![allow(unused)]
fn main() {
    use std::sync::{Arc, Mutex};
    
    let data = Arc::new(Mutex::new(vec![1, 2, 3]));
    let data_clone = data.clone(); // Creates another Arc pointing to the same Mutex
    
    {
        let mut lock = data.lock().unwrap();
        lock.push(4);
    }
    
    // Changes are visible through the clone because they share the same underlying data
    assert_eq!(*data_clone.lock().unwrap(), vec![1, 2, 3, 4]);
}

(Playground)

2 posts - 2 participants

Read full topic

🏷️ Rust_feed