From 526abb3e5b3175008cb60f78b645d5e2c0f5072a Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Tue, 23 Aug 2022 20:37:23 -0700 Subject: * cargo fmt --- src/sync.rs | 75 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 36 deletions(-) (limited to 'src/sync.rs') diff --git a/src/sync.rs b/src/sync.rs index cd626fa..5afa620 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -7,29 +7,32 @@ use core::cell::UnsafeCell; /// /// Provides Synchronization traits. pub mod interface { - /// # Mutex Trait - /// - /// Basic Locking primitive to allow single-process access to data - pub trait Mutex { - /// # The data - /// - /// Each mutex protects some internal data from modification across - /// processes when it is in use. This is important if the process - /// is preempted while the function is using it. - type Data; - /// # Locking mechanism - /// - /// Locks the mutex to access the data in a closure. - /// The data can be read and modified in this closure without worry - /// of poisoning the data across processes. - fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R; - } + /// # Mutex Trait + /// + /// Basic Locking primitive to allow single-process access to data + pub trait Mutex { + /// # The data + /// + /// Each mutex protects some internal data from modification across + /// processes when it is in use. This is important if the process + /// is preempted while the function is using it. + type Data; + /// # Locking mechanism + /// + /// Locks the mutex to access the data in a closure. + /// The data can be read and modified in this closure without worry + /// of poisoning the data across processes. + fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R; + } } /// # Basic Lock Structure -pub struct NullLock where T: ?Sized { - /// The internal data to safely share - data: UnsafeCell, +pub struct NullLock +where + T: ?Sized, +{ + /// The internal data to safely share + data: UnsafeCell, } /// # Allow thread sharing @@ -38,25 +41,25 @@ unsafe impl Send for NullLock where T: ?Sized + Send {} unsafe impl Sync for NullLock where T: ?Sized + Send {} impl NullLock { - /// # Create a new instance of the lock - pub const fn new(data: T) -> Self { - Self { - data: UnsafeCell::new(data), - } - } + /// # Create a new instance of the lock + pub const fn new(data: T) -> Self { + Self { + data: UnsafeCell::new(data), + } + } } impl interface::Mutex for NullLock { - /// # Underlying data of the lock - type Data = T; + /// # Underlying data of the lock + type Data = T; - /// # Locking mechanism - /// - /// Locks the Mutex, and passes a mutable reference - /// to the encapsulated data to a closure. - fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut T) -> R) -> R { - let data = unsafe { &mut *self.data.get() }; + /// # Locking mechanism + /// + /// Locks the Mutex, and passes a mutable reference + /// to the encapsulated data to a closure. + fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut T) -> R) -> R { + let data = unsafe { &mut *self.data.get() }; - f(data) - } + f(data) + } } -- cgit v1.2.1