From 9f4c4bb3183ebe8e27c7393b098caa3e9f9693fd Mon Sep 17 00:00:00 2001 From: Haim Gelfenbeyn Date: Wed, 25 Oct 2023 08:01:02 -0400 Subject: [PATCH] Remove unneeded boxing --- src/app.rs | 2 +- src/platform/pnp_detect_windows.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) 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(),