Skip to main content

PtpInstanceStateMutex

Trait PtpInstanceStateMutex 

Source
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§

Source

fn new(state: PtpInstanceState) -> Self

Creates a new instance of the mutex

Source

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

Source

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".

Implementations on Foreign Types§

Source§

impl PtpInstanceStateMutex for RefCell<PtpInstanceState>

Source§

fn new(state: PtpInstanceState) -> Self

Source§

fn with_ref<R, F: FnOnce(&PtpInstanceState) -> R>(&self, f: F) -> R

Source§

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.
Source§

fn new(state: PtpInstanceState) -> Self

Source§

fn with_ref<R, F: FnOnce(&PtpInstanceState) -> R>(&self, f: F) -> R

Source§

fn with_mut<R, F: FnOnce(&mut PtpInstanceState) -> R>(&self, f: F) -> R

Implementors§