fn with_controller<T, F: FnMut(&Linuxdev) -> device::Result<T>>(&self, controller: DeviceID, mut f: F) -> device::Result<T> {
        if let OsDeviceID::Linuxdev(token) = controller.0 {
            if let Some(dev) = self.evdev_controllers.borrow().get(&token) {
                debug_assert!(dev.is_a_controller_and_evdev_node());
                f(dev)
            } else {
                device::disconnected()    
            }
        } else {
            // Don't panic here. Sometimes the higher layer just passes the DeviceID as-is
            // to use without checking if it is adressed to us in the first place.
            // E.g user calls `controller_axis_state(some_device_that_is_not_a_controller)`.
            device::not_supported_by_device("This device does not refer to a controller")
        }
    }
// We take a closure because we can't return a reference to the DeviceID (it outlives the
// borrow() of self.evdev_controllers).
We take a closure because we can't return a reference to the DeviceID (it outlives the
borrow() of self.evdev_controllers).
We take a closure because we can ' t return a reference to the DeviceID ( it outlives the borrow () of self . evdev_controllers ) .
fn with_controller<T, F: FnMut(&Linuxdev) -> device::Result<T>>(&self, controller: DeviceID, mut f: F) -> device::Result<T> {
        if let OsDeviceID::Linuxdev(token) = controller.0 {
            if let Some(dev) = self.evdev_controllers.borrow().get(&token) {
                debug_assert!(dev.is_a_controller_and_evdev_node());
                f(dev)
            } else {
                device::disconnected()    
            }
        } else {
            // Don't panic here. Sometimes the higher layer just passes the DeviceID as-is
            // to use without checking if it is adressed to us in the first place.
            // E.g user calls `controller_axis_state(some_device_that_is_not_a_controller)`.
            device::not_supported_by_device("This device does not refer to a controller")
        }
    }
fn with_controller < T , F : FnMut ( & Linuxdev ) -> device :: Result < T > > ( & self , controller : DeviceID , mut f : F ) -> device :: Result < T > { if let OsDeviceID :: Linuxdev ( token ) = controller . 0 { if let Some ( dev ) = self . evdev_controllers . borrow ( ) . get ( & token ) { debug_assert ! ( dev is_a_controller_and_evdev_node ( ) ) ; f ( dev ) } else { device :: disconnected ( ) } } else { // Don't panic here. Sometimes the higher layer just passes the DeviceID as-is // to use without checking if it is adressed to us in the first place. // E.g user calls `controller_axis_state(some_device_that_is_not_a_controller)`. device :: not_supported_by_device ( " " ) } }
We take a closure because we can't return a reference to the DeviceID (it outlives the
borrow() of self.evdev_controllers).
We take a closure because we can ' t return a reference to the DeviceID ( it outlives the borrow () of self . evdev_controllers ) .
&self
controller
DeviceID
f
F
&self
controller
DeviceID
f
F