pub trait PtpInstanceStateMutex {
// Required methods
fn new(state: PtpInstanceState) -> Self;
fn with_ref<R, F: FnOnce(&PtpInstanceState) -> R>(&self, f: F) -> R;
fn with_mut<R, F: FnOnce(&mut PtpInstanceState) -> R>(&self, f: F) -> R;
}Expand description
A mutex over a PtpInstanceState
This provides an abstraction for locking state in various environments.
Implementations are provided for core::cell::RefCell and
std::sync::RwLock.
Required Methods§
Sourcefn new(state: PtpInstanceState) -> Self
fn new(state: PtpInstanceState) -> Self
Creates a new instance of the mutex
Sourcefn with_ref<R, F: FnOnce(&PtpInstanceState) -> R>(&self, f: F) -> R
fn with_ref<R, F: FnOnce(&PtpInstanceState) -> R>(&self, f: F) -> R
Takes a shared reference to the contained state and calls f with it
Sourcefn with_mut<R, F: FnOnce(&mut PtpInstanceState) -> R>(&self, f: F) -> R
fn with_mut<R, F: FnOnce(&mut PtpInstanceState) -> R>(&self, f: F) -> R
Takes a mutable reference to the contained state and calls f with it
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl PtpInstanceStateMutex for RefCell<PtpInstanceState>
impl PtpInstanceStateMutex for RefCell<PtpInstanceState>
fn new(state: PtpInstanceState) -> Self
fn with_ref<R, F: FnOnce(&PtpInstanceState) -> R>(&self, f: F) -> R
fn with_mut<R, F: FnOnce(&mut PtpInstanceState) -> R>(&self, f: F) -> R
Source§impl PtpInstanceStateMutex for RwLock<PtpInstanceState>
Available on crate feature std only.
impl PtpInstanceStateMutex for RwLock<PtpInstanceState>
Available on crate feature
std only.