Hi,
I am still new to Rust.
In the following example, I am wrapping an Option in an Arc/Mutex, then I am expecting the lock().unwrap() to grant me access to my option again so I can reference my initial integer. For some reason, I can’t access the option element. I also tried to use MutexGuard’s deref() without success.
How do can I reference my initial integer after wrapping it in an option and an arc/mutex?
Thanks.
use std::sync::Arc;
use std::sync::Mutex;
use std::ops::Deref;
fn main() {
println!("Hello!");
let n:i32 = 5;
let arc = Arc::new(Mutex::new(Some(n)));
let arc_clone = arc.clone();
let ref_n: &i32 = match arc_clone.lock().unwrap() {
Some(ref x) => x,
None => panic!("Error."),
};
println!("{:?}", ref_n);
}