pub struct DeviceContext<S: DeviceState> { /* private fields */ }Expand description
Handle for accessing a DeviceState associated with a specific device.
Implementations§
Source§impl<S: DeviceState> DeviceContext<S>
impl<S: DeviceState> DeviceContext<S>
Sourcepub fn locate<D: Device + 'static>(device: &D) -> Self
pub fn locate<D: Device + 'static>(device: &D) -> Self
Creates a DeviceState handle for the given device.
Registers the device-type combination globally if needed.
Sourcepub fn insert<D: Device + 'static>(
device: &D,
state_new: S,
) -> Result<Self, String>
pub fn insert<D: Device + 'static>( device: &D, state_new: S, ) -> Result<Self, String>
Inserts a new state associated with the device.
§Returns
An error if the device already has a registered state.
Sourcepub fn lock_device(&self) -> DeviceGuard<'_>
pub fn lock_device(&self) -> DeviceGuard<'_>
Locks the current device making sure this device can be used.
Sourcepub 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§
Source§impl<S: DeviceState> Clone for DeviceContext<S>
impl<S: DeviceState> Clone for DeviceContext<S>
impl<S: DeviceState> Sync for DeviceContext<S>
There is nothing to read without a lock, and it’s fine to allow locking a context reference.