From 0be08dc86c2543d8e3aa66d27ef4c2e8e3e7b469 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Wed, 27 Nov 2024 17:13:27 +0800 Subject: [PATCH] feat: impl Into for owned fd types --- 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 ++++++ 6 files changed, 34 insertions(+), 3 deletions(-) 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).