X-Git-Url: https://code.octet-stream.net/netwatcher/blobdiff_plain/74d0fddfbb570514118b4ddc228ce19ccd8bb969..d2c9a9f306a336aa9dd8ddfb6579746e4f10b7a4:/src/watch_win.rs?ds=sidebyside diff --git a/src/watch_win.rs b/src/watch_win.rs index 67e0d4c..23b274e 100644 --- a/src/watch_win.rs +++ b/src/watch_win.rs @@ -19,14 +19,14 @@ use crate::Error; use crate::List; use crate::Update; -pub struct WatchState { +struct WatchState { /// The last result that we captured, for diffing prev_list: List, /// User's callback - cb: Box, + cb: Box, } -pub struct WatchHandle { +pub(crate) struct WatchHandle { hnd: HANDLE, _state: Pin>>, } @@ -39,7 +39,7 @@ impl Drop for WatchHandle { } } -pub(crate) fn watch_interfaces( +pub(crate) fn watch_interfaces( callback: F, ) -> Result { let state = Box::pin(Mutex::new(WatchState { @@ -63,7 +63,7 @@ pub(crate) fn watch_interfaces( // Trigger an initial update. // This is allowed to race with true updates because it // will always calculate a diff and discard no-ops. - handle_notif(&mut *state.lock().unwrap()); + handle_notif(&mut state.lock().unwrap()); // Then return the handle Ok(WatchHandle { hnd, _state: state }) } @@ -81,7 +81,11 @@ unsafe extern "system" fn notif( ) { let state_ptr = ctx as *const Mutex; unsafe { - let state_guard = &mut *state_ptr.as_ref().unwrap().lock().unwrap(); + let state_guard = &mut *state_ptr + .as_ref() + .expect("callback ctx should never be null") + .lock() + .unwrap(); handle_notif(state_guard); } }