1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use std::sync::{Mutex as StdMutex, MutexGuard, PoisonError};

/// Non-poisoning mutex.
pub(crate) struct Mutex<T: ?Sized> {
    std: StdMutex<T>,
}

impl<T> Mutex<T> {
    pub(crate) fn new(value: T) -> Self {
        Mutex {
            std: StdMutex::new(value),
        }
    }
}

impl<T: ?Sized> Mutex<T> {
    pub(crate) fn lock(&self) -> MutexGuard<T> {
        self.std.lock().unwrap_or_else(PoisonError::into_inner)
    }
}