pub struct OwnedMutexGuard<T> where
T: ?Sized, { /* private fields */ }
Expand description
An owned handle to a held Mutex
.
This guard is only available from a Mutex
that is wrapped in an Arc
. It
is identical to MutexGuard
, except that rather than borrowing the Mutex
,
it clones the Arc
, incrementing the reference count. This means that
unlike MutexGuard
, it will have the 'static
lifetime.
As long as you have this guard, you have exclusive access to the underlying
T
. The guard internally keeps a reference-counted pointer to the original
Mutex
, so even if the lock goes away, the guard remains valid.
The lock is automatically released whenever the guard is dropped, at which
point lock
will succeed yet again.
Implementations
impl<T> OwnedMutexGuard<T> where
T: ?Sized,
impl<T> OwnedMutexGuard<T> where
T: ?Sized,
pub fn mutex(this: &OwnedMutexGuard<T>) -> &Arc<Mutex<T>>
pub fn mutex(this: &OwnedMutexGuard<T>) -> &Arc<Mutex<T>>
Returns a reference to the original Arc<Mutex>
.
use std::sync::Arc;
use tokio::sync::{Mutex, OwnedMutexGuard};
async fn unlock_and_relock(guard: OwnedMutexGuard<u32>) -> OwnedMutexGuard<u32> {
println!("1. contains: {:?}", *guard);
let mutex: Arc<Mutex<u32>> = OwnedMutexGuard::mutex(&guard).clone();
drop(guard);
let guard = mutex.lock_owned().await;
println!("2. contains: {:?}", *guard);
guard
}
Trait Implementations
impl<T> Debug for OwnedMutexGuard<T> where
T: Debug + ?Sized,
impl<T> Debug for OwnedMutexGuard<T> where
T: Debug + ?Sized,
impl<T> Deref for OwnedMutexGuard<T> where
T: ?Sized,
impl<T> Deref for OwnedMutexGuard<T> where
T: ?Sized,
type Target = T
type Target = T
The resulting type after dereferencing.
fn deref(&self) -> &<OwnedMutexGuard<T> as Deref>::Target
fn deref(&self) -> &<OwnedMutexGuard<T> as Deref>::Target
Dereferences the value.
impl<T> DerefMut for OwnedMutexGuard<T> where
T: ?Sized,
impl<T> DerefMut for OwnedMutexGuard<T> where
T: ?Sized,
fn deref_mut(&mut self) -> &mut <OwnedMutexGuard<T> as Deref>::Target
fn deref_mut(&mut self) -> &mut <OwnedMutexGuard<T> as Deref>::Target
Mutably dereferences the value.
impl<T> Display for OwnedMutexGuard<T> where
T: Display + ?Sized,
impl<T> Display for OwnedMutexGuard<T> where
T: Display + ?Sized,
impl<T> Drop for OwnedMutexGuard<T> where
T: ?Sized,
impl<T> Drop for OwnedMutexGuard<T> where
T: ?Sized,
impl<T> Sync for OwnedMutexGuard<T> where
T: Send + Sync + ?Sized,
Auto Trait Implementations
impl<T> !RefUnwindSafe for OwnedMutexGuard<T>
impl<T: ?Sized> Send for OwnedMutexGuard<T> where
T: Send,
impl<T: ?Sized> Unpin for OwnedMutexGuard<T>
impl<T> !UnwindSafe for OwnedMutexGuard<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more