+ let state = CallbackState {
+ prev_list: List::default(),
+ callback: Box::new(callback),
+ };
+ // Blocks are Fn, not FnMut
+ let state = Mutex::new(state);
+ let block = RcBlock::new(move |_: NwPath| {
+ let mut state = state.lock().unwrap();
+ let Ok(new_list) = crate::list::list_interfaces() else {
+ return;
+ };
+ if new_list == state.prev_list {
+ return;
+ }
+ let update = Update {
+ interfaces: new_list.0.clone(),
+ diff: new_list.diff_from(&state.prev_list),
+ };
+ (state.callback)(update);
+ state.prev_list = new_list;
+ });
+ let path_monitor: NwPathMonitorT;
+ unsafe {
+ let queue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0);
+ path_monitor = nw_path_monitor_create();
+ nw_path_monitor_set_update_handler(path_monitor, &block);
+ nw_path_monitor_set_queue(path_monitor, queue);
+ nw_path_monitor_start(path_monitor);
+ }
+ Ok(WatchHandle {
+ path_monitor,
+ })