Skip to content

Commit 2ad6187

Browse files
committed
Auto merge of #76969 - withoutboats:rawfd-refexive-traits, r=dtolnay
Make RawFd implement the RawFd traits This PR makes `RawFd` implement `AsRawFd`, `IntoRawFd` and `FromRawFd`, so it can be passed to interfaces that use one of those traits as a bound.
2 parents 7820135 + 35b30e2 commit 2ad6187

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

library/std/src/sys/unix/ext/io.rs

+19
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ pub trait IntoRawFd {
6262
fn into_raw_fd(self) -> RawFd;
6363
}
6464

65+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
66+
impl AsRawFd for RawFd {
67+
fn as_raw_fd(&self) -> RawFd {
68+
*self
69+
}
70+
}
71+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
72+
impl IntoRawFd for RawFd {
73+
fn into_raw_fd(self) -> RawFd {
74+
self
75+
}
76+
}
77+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
78+
impl FromRawFd for RawFd {
79+
unsafe fn from_raw_fd(fd: RawFd) -> RawFd {
80+
fd
81+
}
82+
}
83+
6584
#[stable(feature = "rust1", since = "1.0.0")]
6685
impl AsRawFd for fs::File {
6786
fn as_raw_fd(&self) -> RawFd {

library/std/src/sys/vxworks/ext/io.rs

+19
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ pub trait IntoRawFd {
6363
fn into_raw_fd(self) -> RawFd;
6464
}
6565

66+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
67+
impl AsRawFd for RawFd {
68+
fn as_raw_fd(&self) -> RawFd {
69+
*self
70+
}
71+
}
72+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
73+
impl IntoRawFd for RawFd {
74+
fn into_raw_fd(self) -> RawFd {
75+
self
76+
}
77+
}
78+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
79+
impl FromRawFd for RawFd {
80+
unsafe fn from_raw_fd(fd: RawFd) -> RawFd {
81+
fd
82+
}
83+
}
84+
6685
#[stable(feature = "rust1", since = "1.0.0")]
6786
impl AsRawFd for fs::File {
6887
fn as_raw_fd(&self) -> RawFd {

library/std/src/sys/wasi/ext/io.rs

+19
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ pub trait IntoRawFd {
5252
fn into_raw_fd(self) -> RawFd;
5353
}
5454

55+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
56+
impl AsRawFd for RawFd {
57+
fn as_raw_fd(&self) -> RawFd {
58+
*self
59+
}
60+
}
61+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
62+
impl IntoRawFd for RawFd {
63+
fn into_raw_fd(self) -> RawFd {
64+
self
65+
}
66+
}
67+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
68+
impl FromRawFd for RawFd {
69+
unsafe fn from_raw_fd(fd: RawFd) -> RawFd {
70+
fd
71+
}
72+
}
73+
5574
impl AsRawFd for net::TcpStream {
5675
fn as_raw_fd(&self) -> RawFd {
5776
self.as_inner().fd().as_raw()

0 commit comments

Comments
 (0)