Skip to content

Commit 7153ba1

Browse files
authored
feat: impl Into<OwnedFd> for owned fd types (#2548)
1 parent 1f1fb34 commit 7153ba1

File tree

7 files changed

+35
-3
lines changed

7 files changed

+35
-3
lines changed

changelog/2548.added.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implements `Into<OwnedFd>` for `PtyMaster/Fanotify/Inotify/SignalFd/TimerFd`

src/pty.rs

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ impl AsFd for PtyMaster {
6464
}
6565
}
6666

67+
impl From<PtyMaster> for OwnedFd {
68+
fn from(value: PtyMaster) -> Self {
69+
value.0
70+
}
71+
}
72+
6773
impl IntoRawFd for PtyMaster {
6874
fn into_raw_fd(self) -> RawFd {
6975
let fd = self.0;

src/sys/eventfd.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ impl AsRawFd for EventFd {
101101
self.0.as_raw_fd()
102102
}
103103
}
104+
104105
impl From<EventFd> for OwnedFd {
105-
fn from(x: EventFd) -> OwnedFd {
106-
x.0
106+
fn from(value: EventFd) -> Self {
107+
value.0
107108
}
108-
}
109+
}

src/sys/fanotify.rs

+6
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,9 @@ impl AsFd for Fanotify {
418418
self.fd.as_fd()
419419
}
420420
}
421+
422+
impl From<Fanotify> for OwnedFd {
423+
fn from(value: Fanotify) -> Self {
424+
value.fd
425+
}
426+
}

src/sys/inotify.rs

+6
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,9 @@ impl AsFd for Inotify {
254254
self.fd.as_fd()
255255
}
256256
}
257+
258+
impl From<Inotify> for OwnedFd {
259+
fn from(value: Inotify) -> Self {
260+
value.fd
261+
}
262+
}

src/sys/signalfd.rs

+6
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ impl AsRawFd for SignalFd {
147147
}
148148
}
149149

150+
impl From<SignalFd> for OwnedFd {
151+
fn from(value: SignalFd) -> Self {
152+
value.0
153+
}
154+
}
155+
150156
impl Iterator for SignalFd {
151157
type Item = siginfo;
152158

src/sys/timerfd.rs

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ impl FromRawFd for TimerFd {
5858
}
5959
}
6060

61+
impl From<TimerFd> for OwnedFd {
62+
fn from(value: TimerFd) -> Self {
63+
value.fd
64+
}
65+
}
66+
6167
libc_enum! {
6268
/// The type of the clock used to mark the progress of the timer. For more
6369
/// details on each kind of clock, please refer to [timerfd_create(2)](https://man7.org/linux/man-pages/man2/timerfd_create.2.html).

0 commit comments

Comments
 (0)