pub struct Guard<'a, T: ?Sized, B: Backend> { /* private fields */ }
Expand description
A lock guard.
Allows mutual exclusion primitives that implement the Backend
trait to automatically unlock
when a guard goes out of scope. It also provides a safe and convenient way to access the data
protected by the lock.
Implementations§
Source§impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B>
impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B>
Sourcepub fn lock_ref(&self) -> &'a Lock<T, B>
pub fn lock_ref(&self) -> &'a Lock<T, B>
Returns the lock that this guard originates from.
§Examples
The following example shows how to use Guard::lock_ref()
to assert the corresponding
lock is held.
fn assert_held<T, B: Backend>(guard: &Guard<'_, T, B>, lock: &Lock<T, B>) {
// Address-equal means the same lock.
assert!(core::ptr::eq(guard.lock_ref(), lock));
}
// Creates a new lock on the stack.
stack_pin_init!{
let l = new_spinlock!(42)
}
let g = l.lock();
// `g` originates from `l`.
assert_held(&g, &l);
Trait Implementations§
impl<T: Sync + ?Sized, B: Backend> Sync for Guard<'_, T, B>
Auto Trait Implementations§
impl<'a, T, B> Freeze for Guard<'a, T, B>
impl<'a, T, B> !RefUnwindSafe for Guard<'a, T, B>
impl<'a, T, B> !Send for Guard<'a, T, B>
impl<'a, T, B> Unpin for Guard<'a, T, B>
impl<'a, T, B> !UnwindSafe for Guard<'a, T, B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more