diff --git a/src/stream.rs b/src/stream.rs index 2922436..eead53e 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -1,6 +1,6 @@ use std::{ io, - os::unix::io::{AsRawFd, RawFd}, + os::unix::io::AsRawFd, pin::Pin, sync::Arc, task::{Context, Poll}, @@ -20,7 +20,7 @@ use crate::Inotify; /// Allows for streaming events returned by [`Inotify::into_event_stream`]. #[derive(Debug)] pub struct EventStream { - fd: AsyncFd, + fd: AsyncFd>, buffer: T, buffer_pos: usize, unused_bytes: usize, @@ -33,7 +33,7 @@ where /// Returns a new `EventStream` associated with the default reactor. pub(crate) fn new(fd: Arc, buffer: T) -> io::Result { Ok(EventStream { - fd: AsyncFd::new(ArcFdGuard(fd))?, + fd: AsyncFd::new(fd)?, buffer, buffer_pos: 0, unused_bytes: 0, @@ -43,13 +43,13 @@ where /// Returns an instance of `Watches` to add and remove watches. /// See [`Watches::add`] and [`Watches::remove`]. pub fn watches(&self) -> Watches { - Watches::new(self.fd.get_ref().0.clone()) + Watches::new(self.fd.get_ref().clone()) } /// Consumes the `EventStream` instance and returns an `Inotify` using the original /// file descriptor that was passed from `Inotify` to create the `EventStream`. pub fn into_inotify(self) -> Inotify { - Inotify::from_file_descriptor(self.fd.into_inner().0) + Inotify::from_file_descriptor(self.fd.into_inner()) } } @@ -79,7 +79,7 @@ where // there, and we only take complete events out. That means we have at // least one event in there and can call `from_buffer` to take it out. let (bytes_consumed, event) = Event::from_buffer( - Arc::downgrade(&self_.fd.get_ref().0), + Arc::downgrade(self_.fd.get_ref()), &self_.buffer.as_ref()[self_.buffer_pos..], ); self_.buffer_pos += bytes_consumed; @@ -89,17 +89,11 @@ where } } -// Newtype wrapper because AsRawFd isn't implemented for Arc where T: AsRawFd. -#[derive(Debug)] -struct ArcFdGuard(Arc); - -impl AsRawFd for ArcFdGuard { - fn as_raw_fd(&self) -> RawFd { - self.0.as_raw_fd() - } -} - -fn read(fd: &AsyncFd, buffer: &mut [u8], cx: &mut Context) -> Poll> { +fn read( + fd: &AsyncFd>, + buffer: &mut [u8], + cx: &mut Context, +) -> Poll> { let mut guard = ready!(fd.poll_read_ready(cx))?; let result = guard.try_io(|_| { let read = read_into_buffer(fd.as_raw_fd(), buffer);