diff --git a/src/app.rs b/src/app.rs index 3c3cfff..e346bb3 100644 --- a/src/app.rs +++ b/src/app.rs @@ -47,7 +47,7 @@ impl App { pub fn run(self) -> Result<()> { display_control::log_current_source(); - let pnp_detector = PnPDetect::new(Box::new(self)); + let pnp_detector = PnPDetect::new(&self); pnp_detector.detect()?; Ok(()) diff --git a/src/platform/pnp_detect_windows.rs b/src/platform/pnp_detect_windows.rs index baad0eb..32dca93 100644 --- a/src/platform/pnp_detect_windows.rs +++ b/src/platform/pnp_detect_windows.rs @@ -22,14 +22,14 @@ use winapi::um::winuser::{ /// Detection of plugged in / removed USB devices on Windows: listens for WM_DEVICECHANGE messages. /// This code should be removed once libusb supports hotplug notifications on Windows: /// https://github.com/libusb/libusb/issues/86 -pub struct PnPDetectWindows { +pub struct PnPDetectWindows<'a> { hwnd: HWND, - callback: Box, + callback: &'a dyn UsbCallback, current_devices: HashSet, } -impl PnPDetectWindows { - pub fn new(callback: Box) -> Self { +impl<'a> PnPDetectWindows<'a> { + pub fn new(callback: &'a (dyn UsbCallback + 'a)) -> Self { let mut pnp_detect = Self { callback, current_devices: Self::read_device_list().unwrap_or_default(),