You want to realize getting the event of disconnecting and connecting Input devices using udev monitor.
Code:
if let Ok(context) = libudev::Context::new() { if let Ok(mut monitor) = libudev::Monitor::new(&context){ if let Err(e) = monitor.match_subsystem("input") { return Err(X::err_init_match_udev(e)); } if let Ok(mut listen) = monitor.listen(){ loop { //let mut unique = Vec::new(); //println!("CIKLE"); for device in listen.receive_event() { let mut path = device.syspath(); println!("found device: {:?} is_dir:{}, is_file:{}, exists:{}", path, path.is_dir(), path.is_file(), path.exists()); input.recreate_all_device(); } } return Ok(()); } return Err(X::err_init_monitor_listen_udev); } return Err(X::err_init_monitor_udev); } Err(X::err_init_context_udev) Problem: 1. A lot of events come place 1, disconnected or connected.
Problem: 2. The flow is not blocked at all, the flow flows into the eternal cycle.
Dependencies: libudev https://docs.rs/libudev/0.2.0/libudev/
loop{ for device ... }there is neither abreaknor areturn. - red75primreceive_event: "This method does not block". This method is not blocking. It returnsNoneimmediately if there are no events. - red75prim