Type Definition spinning_top::MappedSpinlockGuard[][src]

type MappedSpinlockGuard<'a, T> = MappedMutexGuard<'a, RawSpinlock, T>;
Expand description

A RAII guard returned by SpinlockGuard::map.

Example

use spinning_top::{MappedSpinlockGuard, Spinlock, SpinlockGuard};

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

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

    // Map the internal value of `gurad`. `guard` is moved.
    let mut mapped: MappedSpinlockGuard<'_, _> =
        SpinlockGuard::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));