Change Mutex content in Rust
A snippet is worth a thousand words.
// Define a simple boolean value as false
let booleana: bool = false;
// No surprises if we access the element
println!("Result pre-scope: {}", *booleana.lock().unwrap()); // -> false
{
let mut m = booleana.lock().unwrap();
*m = true; // you should dereference to change the content
println!("Result in-scope: {}", m); // -> true // success!
}
// The new value is retained out of scope
println!("Result post-scope: {}", *booleana.lock().unwrap()); // -> true
support
Did you find this post useful?
Remember that this website doesn’t make use of any trackers or analytics or adv so it doesn’t earn from your visits (moreover, it has a minimal environmental impact).
If you like this blog, refill my caffeine supplies by
share