From 16d867ba66c1791536f6f54b846b7ee3623ff721 Mon Sep 17 00:00:00 2001
From: Hugo Osvaldo Barrera <hugo@whynothugo.nl>
Date: Tue, 14 Jan 2025 11:23:18 +0100
Subject: [PATCH] Drop ArcFdGuard newtype

This type existed because AsRawFd was not implemented for `Arc<T> where
T: AsRawFd`.

As for 1.63.0, the following implementation is provided:

    impl<T: AsRawFd> AsRawFd for Arc<T>

The current MSRV is 1.70, so we can rely on this new implementation.

Drop the newtype wrapper, and rely on the new stdlib implementation
instead.
---
 src/stream.rs | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

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<T> {
-    fd: AsyncFd<ArcFdGuard>,
+    fd: AsyncFd<Arc<FdGuard>>,
     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<FdGuard>, buffer: T) -> io::Result<Self> {
         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<T> where T: AsRawFd.
-#[derive(Debug)]
-struct ArcFdGuard(Arc<FdGuard>);
-
-impl AsRawFd for ArcFdGuard {
-    fn as_raw_fd(&self) -> RawFd {
-        self.0.as_raw_fd()
-    }
-}
-
-fn read(fd: &AsyncFd<ArcFdGuard>, buffer: &mut [u8], cx: &mut Context) -> Poll<io::Result<usize>> {
+fn read(
+    fd: &AsyncFd<Arc<FdGuard>>,
+    buffer: &mut [u8],
+    cx: &mut Context,
+) -> Poll<io::Result<usize>> {
     let mut guard = ready!(fd.poll_read_ready(cx))?;
     let result = guard.try_io(|_| {
         let read = read_into_buffer(fd.as_raw_fd(), buffer);