with_device

Function with_device 

Source
pub fn with_device<F, T, E>(
    device: Option<Rc<RefCell<Device>>>,
    f: F,
) -> Result<T, E>
where F: FnOnce(&mut Device) -> Result<T, E>, E: From<DeviceError>,
Expand description

Executes a closure with a mutable reference to a Device.

This helper function centralizes the boilerplate for safely acquiring a mutable borrow of a Device from the shared Rc<RefCell<...>>.

§Errors

Returns an error if the device is not available or is already borrowed. The error is converted into the caller’s error type E.