evdev-rs
evdev-rs copied to clipboard
Implement AsRawFd for Device
provides compatibility with smol::Async for polling from async contexts:
// Setup async device wrapper (configures device file descriptor with `O_NONBLOCK`)
let a = smol::Async::new(d)?;
// Async poll for the next event
let (_status, event) = a.read_with(|d| d.next_event(ReadFlag::NORMAL) ).await?;
for convenience Device also really needs to be Sync, which it is not automatically due to the internal *mut raw::libevdev, however, i can't see from the evdev docs whether this is reasonable or not?
I haven't used Sync myself before so I need to look into it a bit more. Other things look good to me.
having another look at this it appears y'all already have interior mutability with raw: *mut raw::libevdev so the borrow checker will allow multiple references which all can be (internally) mutated and adding Sync would let this occur across threads, which could expound any existing unsoundness.
i am however not sure how to mitigate this :-/