Skip to content

feat: impl Into<OwnedFd> for owned fd types #2548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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