diff --git a/src/macros.rs b/src/macros.rs index 3a0f56f..e06a39e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -10,12 +10,12 @@ macro_rules! c_str { macro_rules! file_descriptor_type { ($type:ident) => { #[repr(transparent)] - pub struct $type(RawFd); + pub struct $type(::std::os::unix::io::RawFd); file_descriptor_impl!($type); - impl FromRawFd for $type { - unsafe fn from_raw_fd(fd: RawFd) -> Self { + impl ::std::os::unix::io::FromRawFd for $type { + unsafe fn from_raw_fd(fd: ::std::os::unix::io::RawFd) -> Self { Self(fd) } } @@ -34,14 +34,20 @@ macro_rules! file_descriptor_impl { } } - impl AsRawFd for $type { - fn as_raw_fd(&self) -> RawFd { + impl ::std::os::unix::io::AsFd for $type { + fn as_fd(&self) -> ::std::os::unix::io::BorrowedFd<'_> { + unsafe { ::std::os::unix::io::BorrowedFd::borrow_raw(self.0) } + } + } + + impl ::std::os::unix::io::AsRawFd for $type { + fn as_raw_fd(&self) -> ::std::os::unix::io::RawFd { self.0 } } - impl IntoRawFd for $type { - fn into_raw_fd(mut self) -> RawFd { + impl ::std::os::unix::io::IntoRawFd for $type { + fn into_raw_fd(mut self) -> ::std::os::unix::io::RawFd { let fd = self.0; self.0 = -libc::EBADF; fd diff --git a/src/nsfd.rs b/src/nsfd.rs index 9a98ed0..18f5e7d 100644 --- a/src/nsfd.rs +++ b/src/nsfd.rs @@ -4,7 +4,7 @@ use std::ffi::CStr; use std::io; use std::marker::PhantomData; use std::os::raw::c_int; -use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +use std::os::unix::io::RawFd; pub mod ns_type { pub trait NsType { diff --git a/src/tools.rs b/src/tools.rs index 759346b..36c78c4 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -3,7 +3,7 @@ //! Note that this should stay small, otherwise we should introduce a dependency on our `proxmox` //! crate as that's where we have all this stuff usually... -use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd}; /// Guard a raw file descriptor with a drop handler. This is mostly useful when access to an owned /// `RawFd` is required without the corresponding handler object (such as when only the file