with_device

Function with_device 

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

Executes a closure with a mutable reference to a TpmDevice.

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

§Errors

Returns NotAvailable when no device is present and AlreadyBorrowed when the device is already mutably borrowed, both converted into the caller’s error type E. Propagates any error returned by the closure f.