From 7153ba17eb4ab086fd5ca3e3f0b9be6ce6fc8f51 Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Wed, 27 Nov 2024 17:44:28 +0800 Subject: [PATCH] feat: impl Into for owned fd types (#2548) --- changelog/2548.added.md | 1 + src/pty.rs | 6 ++++++ src/sys/eventfd.rs | 7 ++++--- src/sys/fanotify.rs | 6 ++++++ src/sys/inotify.rs | 6 ++++++ src/sys/signalfd.rs | 6 ++++++ src/sys/timerfd.rs | 6 ++++++ 7 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 changelog/2548.added.md diff --git a/changelog/2548.added.md b/changelog/2548.added.md new file mode 100644 index 0000000000..60b2ae5428 --- /dev/null +++ b/changelog/2548.added.md @@ -0,0 +1 @@ +Implements `Into` for `PtyMaster/Fanotify/Inotify/SignalFd/TimerFd` diff --git a/src/pty.rs b/src/pty.rs index b702de8d96..5211d16075 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -64,6 +64,12 @@ impl AsFd for PtyMaster { } } +impl From for OwnedFd { + fn from(value: PtyMaster) -> Self { + value.0 + } +} + impl IntoRawFd for PtyMaster { fn into_raw_fd(self) -> RawFd { let fd = self.0; diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs index 8c8c923f35..b7860e683f 100644 --- a/src/sys/eventfd.rs +++ b/src/sys/eventfd.rs @@ -101,8 +101,9 @@ impl AsRawFd for EventFd { self.0.as_raw_fd() } } + impl From for OwnedFd { - fn from(x: EventFd) -> OwnedFd { - x.0 + fn from(value: EventFd) -> Self { + value.0 } -} +} \ No newline at end of file diff --git a/src/sys/fanotify.rs b/src/sys/fanotify.rs index 43017a217f..cf07fdb719 100644 --- a/src/sys/fanotify.rs +++ b/src/sys/fanotify.rs @@ -418,3 +418,9 @@ impl AsFd for Fanotify { self.fd.as_fd() } } + +impl From for OwnedFd { + fn from(value: Fanotify) -> Self { + value.fd + } +} \ No newline at end of file diff --git a/src/sys/inotify.rs b/src/sys/inotify.rs index ee87a87d36..0a9abf39e6 100644 --- a/src/sys/inotify.rs +++ b/src/sys/inotify.rs @@ -254,3 +254,9 @@ impl AsFd for Inotify { self.fd.as_fd() } } + +impl From for OwnedFd { + fn from(value: Inotify) -> Self { + value.fd + } +} \ No newline at end of file diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs index 33fecc0dc7..61604f0552 100644 --- a/src/sys/signalfd.rs +++ b/src/sys/signalfd.rs @@ -147,6 +147,12 @@ impl AsRawFd for SignalFd { } } +impl From for OwnedFd { + fn from(value: SignalFd) -> Self { + value.0 + } +} + impl Iterator for SignalFd { type Item = siginfo; diff --git a/src/sys/timerfd.rs b/src/sys/timerfd.rs index 2fad7d8fd0..21e2c4aa10 100644 --- a/src/sys/timerfd.rs +++ b/src/sys/timerfd.rs @@ -58,6 +58,12 @@ impl FromRawFd for TimerFd { } } +impl From for OwnedFd { + fn from(value: TimerFd) -> Self { + value.fd + } +} + libc_enum! { /// The type of the clock used to mark the progress of the timer. For more /// details on each kind of clock, please refer to [timerfd_create(2)](https://man7.org/linux/man-pages/man2/timerfd_create.2.html).