Struct DeviceContext
pub struct DeviceContext<S>where
S: DeviceState,{ /* private fields */ }Expand description
Handle for accessing a DeviceState associated with a specific device.
Implementations§
§impl<S> DeviceContext<S>where
S: DeviceState,
impl<S> DeviceContext<S>where
S: DeviceState,
pub fn locate<D>(device: &D) -> DeviceContext<S>where
D: Device + 'static,
pub fn locate<D>(device: &D) -> DeviceContext<S>where
D: Device + 'static,
Creates a DeviceState handle for the given device.
Registers the device-type combination globally if needed.
pub fn insert<D>(device: &D, state_new: S) -> Result<DeviceContext<S>, String>where
D: Device + 'static,
pub fn insert<D>(device: &D, state_new: S) -> Result<DeviceContext<S>, String>where
D: Device + 'static,
Inserts a new state associated with the device.
§Returns
An error if the device already has a registered state.
pub fn lock_device(&self) -> DeviceGuard<'_>
pub fn lock_device(&self) -> DeviceGuard<'_>
Locks the current device making sure this device can be used.
pub fn lock(&self) -> DeviceStateGuard<'_, S>
pub fn lock(&self) -> DeviceStateGuard<'_, S>
Acquires exclusive mutable access to the DeviceState.
The same device can lock multiple types at the same time.
§Panics
If the same state type is locked multiple times on the same thread. This can only happen with recursive locking of the same state, which isn’t allowed since having multiple mutable references to the same state isn’t valid.
Trait Implementations§
§impl<S> Clone for DeviceContext<S>where
S: DeviceState,
impl<S> Clone for DeviceContext<S>where
S: DeviceState,
§fn clone(&self) -> DeviceContext<S>
fn clone(&self) -> DeviceContext<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<S> Sync for DeviceContext<S>where
S: DeviceState,
There is nothing to read without a lock, and it’s fine to allow locking a context reference.
Auto Trait Implementations§
impl<S> Freeze for DeviceContext<S>
impl<S> !RefUnwindSafe for DeviceContext<S>
impl<S> Send for DeviceContext<S>
impl<S> Unpin for DeviceContext<S>where
S: Unpin,
impl<S> !UnwindSafe for DeviceContext<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more