hi folks! I am wondering if it is possible to maybe get a ref or a mut ref to a value stored inside an Arc<Mutex<Option<T>>>
I know I can get a MutexGuard<'a, Option<T>> by calling self.0.lock()
However, if I call self.0.lock().as_ref().unwrap(), or self.0.lock().as_mut().unwrap() in get and get_mut respectively, the MutexGuard is not maintained when passing out of the function.
What can be done in this situation? I would like for the lock to be maintained, if possible.
Am I making some kind of conceptual error here?
when I say maybe get a ref, what I mean is that I want the function to unwrap the option (or at least reroute somehow if the option is not available)
This is mainly to avoid having to call .lock().as_ref().unwrap() on every access to the underlying T.
I would rather be able to simply call .get() or .get_mut() depending on the usage
I have the following: ```rust
#[derive(Default)]
pub struct Amo<T>(Arc<Mutex<Option<T>>>);
impl<T> Amo<T> {
delegate!{
to self.0.lock() {
pub fn is_some(&self) -> bool;
pub fn is_none(&self) -> bool;
}
}
pub fn get<'a>(&'a self) -> MutexGuard<'a, &T> {
todo!();
}
pub fn get_mut<'a>(&'a mut self) -> MutexGuard<'a, &'a mut T> {
todo!();
}
}