diff --git a/src/evdev.rs b/src/evdev.rs index 1a8b2cb..7cf26f0 100644 --- a/src/evdev.rs +++ b/src/evdev.rs @@ -4,6 +4,7 @@ use std::{io, fs}; use std::mem::{MaybeUninit, size_of}; use std::slice::from_raw_parts_mut; use std::os::unix::io::{RawFd, AsRawFd, IntoRawFd, FromRawFd}; +use std::os::fd::{AsFd, BorrowedFd}; use nix; use crate::sys; use crate::{ @@ -41,6 +42,14 @@ impl EvdevHandle { } } +impl AsFd for EvdevHandle { + fn as_fd<'a>(&'a self) -> BorrowedFd<'a> { + unsafe { + BorrowedFd::borrow_raw(self.fd()) + } + } +} + impl AsRawFd for EvdevHandle { fn as_raw_fd(&self) -> RawFd { self.fd() diff --git a/src/uinput.rs b/src/uinput.rs index 6580372..9bdcc3d 100644 --- a/src/uinput.rs +++ b/src/uinput.rs @@ -4,6 +4,7 @@ use std::{io, fs, ptr}; use std::os::unix::io::{RawFd, AsRawFd, IntoRawFd, FromRawFd}; use std::os::unix::ffi::OsStrExt; +use std::os::fd::{AsFd, BorrowedFd}; use std::os::raw::c_char; use std::mem::{MaybeUninit, size_of}; use std::path::{Path, PathBuf}; @@ -12,7 +13,7 @@ use std::ffi::{OsStr, OsString, CStr}; use crate::sys; use nix; use crate::{Key, InputId, AbsoluteInfoSetup, kinds}; -use crate::macros::{convert_error}; +use crate::macros::convert_error; pub use crate::sys::{UINPUT_MAX_NAME_SIZE, UINPUT_VERSION}; @@ -54,6 +55,14 @@ impl UInputHandle { } } +impl AsFd for UInputHandle { + fn as_fd<'a>(&'a self) -> BorrowedFd<'a> { + unsafe { + BorrowedFd::borrow_raw(self.fd()) + } + } +} + impl IntoRawFd for UInputHandle { fn into_raw_fd(self) -> RawFd { self.0.into_raw_fd()