1 use core::cell::{RefCell, RefMut};
2 use core::ops::{Deref, DerefMut};
4 pub type LockResult<Guard> = Result<Guard, ()>;
6 pub struct Mutex<T: ?Sized> {
10 #[must_use = "if unused the Mutex will immediately unlock"]
11 pub struct MutexGuard<'a, T: ?Sized + 'a> {
15 impl<T: ?Sized> Deref for MutexGuard<'_, T> {
18 fn deref(&self) -> &T {
23 impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
24 fn deref_mut(&mut self) -> &mut T {
30 pub fn new(inner: T) -> Mutex<T> {
31 Mutex { inner: RefCell::new(inner) }
34 pub fn lock<'a>(&'a self) -> LockResult<MutexGuard<'a, T>> {
35 Ok(MutexGuard { lock: self.inner.borrow_mut() })