pub type MappedBackoffSpinlockGuard<'a, T> = MappedMutexGuard<'a, RawSpinlock<Backoff>, T>;
Expand description

A RAII guard returned by BackoffSpinlockGuard::map.

Example

use spinning_top::{
    guard::{BackoffSpinlockGuard, MappedBackoffSpinlockGuard},
    BackoffSpinlock,
};

let spinlock = BackoffSpinlock::new(Some(3));

// Begin a new scope.
{
    // Lock the spinlock to create a `BackoffSpinlockGuard`.
    let mut guard: BackoffSpinlockGuard<_> = spinlock.lock();

    // Map the internal value of `guard`. `guard` is moved.
    let mut mapped: MappedBackoffSpinlockGuard<'_, _> =
        BackoffSpinlockGuard::map(guard, |g| g.as_mut().unwrap());
    assert_eq!(*mapped, 3);

    *mapped = 5;
    assert_eq!(*mapped, 5);
} // `mapped` is dropped -> frees the spinlock again.

// The operation is reflected to the original lock.
assert_eq!(*spinlock.lock(), Some(5));

Aliased Type§

struct MappedBackoffSpinlockGuard<'a, T> { /* private fields */ }