Skip to content

Commit

Permalink
feat: impl Into<OwnedFd> for owned fd types
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC committed Nov 27, 2024
1 parent 1f1fb34 commit 17c8bd6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/2548.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements `Into<OwnedFd>` for `PtyMaster/Fanotify/Inotify/SignalFd/TimerFd`
6 changes: 6 additions & 0 deletions src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ impl AsFd for PtyMaster {
}
}

impl From<PtyMaster> for OwnedFd {
fn from(value: PtyMaster) -> Self {
value.0
}
}

impl IntoRawFd for PtyMaster {
fn into_raw_fd(self) -> RawFd {
let fd = self.0;
Expand Down
7 changes: 4 additions & 3 deletions src/sys/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ impl AsRawFd for EventFd {
self.0.as_raw_fd()
}
}

impl From<EventFd> for OwnedFd {
fn from(x: EventFd) -> OwnedFd {
x.0
fn from(value: EventFd) -> Self {
value.0
}
}
}
6 changes: 6 additions & 0 deletions src/sys/fanotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,9 @@ impl AsFd for Fanotify {
self.fd.as_fd()
}
}

impl From<Fanotify> for OwnedFd {
fn from(value: Fanotify) -> Self {
value.fd
}
}
6 changes: 6 additions & 0 deletions src/sys/inotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,9 @@ impl AsFd for Inotify {
self.fd.as_fd()
}
}

impl From<Inotify> for OwnedFd {
fn from(value: Inotify) -> Self {
value.fd
}
}
6 changes: 6 additions & 0 deletions src/sys/signalfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ impl AsRawFd for SignalFd {
}
}

impl From<SignalFd> for OwnedFd {
fn from(value: SignalFd) -> Self {
value.0
}
}

impl Iterator for SignalFd {
type Item = siginfo;

Expand Down
6 changes: 6 additions & 0 deletions src/sys/timerfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ impl FromRawFd for TimerFd {
}
}

impl From<TimerFd> 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).
Expand Down

0 comments on commit 17c8bd6

Please sign in to comment.