NoopMutex does not require an UnsafeCell

This commit is contained in:
huntc 2021-07-11 12:05:50 +10:00
parent 9b5f2e465b
commit 5a5795ef2b

View File

@ -108,20 +108,18 @@ pub fn in_thread_mode() -> bool {
/// A "mutex" that does nothing and cannot be shared between threads. /// A "mutex" that does nothing and cannot be shared between threads.
pub struct NoopMutex<T> { pub struct NoopMutex<T> {
inner: UnsafeCell<T>, inner: T,
} }
impl<T> NoopMutex<T> { impl<T> NoopMutex<T> {
pub const fn new(value: T) -> Self { pub const fn new(value: T) -> Self {
NoopMutex { NoopMutex { inner: value }
inner: UnsafeCell::new(value),
}
} }
} }
impl<T> NoopMutex<T> { impl<T> NoopMutex<T> {
pub fn borrow(&self) -> &T { pub fn borrow(&self) -> &T {
unsafe { &*self.inner.get() } &self.inner
} }
} }