1#[cfg(target_os = "hermit")]
8use std::os::hermit::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
9#[cfg(unix)]
10use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
11#[cfg(target_os = "wasi")]
12use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
13#[cfg(windows)]
14use std::os::windows::io::{
15 AsRawHandle, AsRawSocket, FromRawHandle, FromRawSocket, IntoRawHandle, IntoRawSocket,
16 RawHandle, RawSocket,
17};
18
19#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
24pub type RawFilelike = RawFd;
25
26#[cfg(windows)]
31pub type RawFilelike = RawHandle;
32
33#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
38pub type RawSocketlike = RawFd;
39
40#[cfg(windows)]
45pub type RawSocketlike = RawSocket;
46
47#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
52pub trait AsRawFilelike: AsRawFd {
53 fn as_raw_filelike(&self) -> RawFilelike;
55}
56
57#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
58impl<T: AsRawFd> AsRawFilelike for T {
59 #[inline]
60 fn as_raw_filelike(&self) -> RawFilelike {
61 self.as_raw_fd()
62 }
63}
64
65#[cfg(windows)]
68pub trait AsRawFilelike: AsRawHandle {
69 fn as_raw_filelike(&self) -> RawFilelike;
71}
72
73#[cfg(windows)]
74impl<T: AsRawHandle> AsRawFilelike for T {
75 #[inline]
76 fn as_raw_filelike(&self) -> RawFilelike {
77 self.as_raw_handle()
78 }
79}
80
81#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
84pub trait AsRawSocketlike: AsRawFd {
85 fn as_raw_socketlike(&self) -> RawSocketlike;
87}
88
89#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
90impl<T: AsRawFd> AsRawSocketlike for T {
91 #[inline]
92 fn as_raw_socketlike(&self) -> RawSocketlike {
93 self.as_raw_fd()
94 }
95}
96
97#[cfg(windows)]
100pub trait AsRawSocketlike: AsRawSocket {
101 fn as_raw_socketlike(&self) -> RawSocketlike;
103}
104
105#[cfg(windows)]
106impl<T: AsRawSocket> AsRawSocketlike for T {
107 #[inline]
108 fn as_raw_socketlike(&self) -> RawSocketlike {
109 self.as_raw_socket()
110 }
111}
112
113#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
116pub trait IntoRawFilelike: IntoRawFd {
117 fn into_raw_filelike(self) -> RawFilelike;
119}
120
121#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
122impl<T: IntoRawFd> IntoRawFilelike for T {
123 #[inline]
124 fn into_raw_filelike(self) -> RawFilelike {
125 self.into_raw_fd()
126 }
127}
128
129#[cfg(windows)]
132pub trait IntoRawFilelike: IntoRawHandle {
133 fn into_raw_filelike(self) -> RawFilelike;
135}
136
137#[cfg(windows)]
138impl<T: IntoRawHandle> IntoRawFilelike for T {
139 #[inline]
140 fn into_raw_filelike(self) -> RawFilelike {
141 self.into_raw_handle()
142 }
143}
144
145#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
148pub trait IntoRawSocketlike: IntoRawFd {
149 fn into_raw_socketlike(self) -> RawSocketlike;
151}
152
153#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
154impl<T: IntoRawFd> IntoRawSocketlike for T {
155 #[inline]
156 fn into_raw_socketlike(self) -> RawSocketlike {
157 self.into_raw_fd()
158 }
159}
160
161#[cfg(windows)]
164pub trait IntoRawSocketlike: IntoRawSocket {
165 fn into_raw_socketlike(self) -> RawSocketlike;
167}
168
169#[cfg(windows)]
170impl<T: IntoRawSocket> IntoRawSocketlike for T {
171 #[inline]
172 fn into_raw_socketlike(self) -> RawSocketlike {
173 self.into_raw_socket()
174 }
175}
176
177#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
180pub trait FromRawFilelike: FromRawFd {
181 unsafe fn from_raw_filelike(raw: RawFilelike) -> Self;
191}
192
193#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
194impl<T: FromRawFd> FromRawFilelike for T {
195 #[inline]
196 unsafe fn from_raw_filelike(raw: RawFilelike) -> Self {
197 Self::from_raw_fd(raw)
198 }
199}
200
201#[cfg(windows)]
204pub trait FromRawFilelike: FromRawHandle {
205 unsafe fn from_raw_filelike(raw: RawFilelike) -> Self;
207}
208
209#[cfg(windows)]
210impl<T: FromRawHandle> FromRawFilelike for T {
211 #[inline]
212 unsafe fn from_raw_filelike(raw: RawFilelike) -> Self {
213 Self::from_raw_handle(raw)
214 }
215}
216
217#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
220pub trait FromRawSocketlike: FromRawFd {
221 unsafe fn from_raw_socketlike(raw: RawSocketlike) -> Self;
231}
232
233#[cfg(any(unix, target_os = "wasi", target_os = "hermit"))]
234impl<T: FromRawFd> FromRawSocketlike for T {
235 #[inline]
236 unsafe fn from_raw_socketlike(raw: RawSocketlike) -> Self {
237 Self::from_raw_fd(raw)
238 }
239}
240
241#[cfg(windows)]
244pub trait FromRawSocketlike: FromRawSocket {
245 unsafe fn from_raw_socketlike(raw: RawSocketlike) -> Self;
247}
248
249#[cfg(windows)]
250impl<T: FromRawSocket> FromRawSocketlike for T {
251 #[inline]
252 unsafe fn from_raw_socketlike(raw: RawSocketlike) -> Self {
253 Self::from_raw_socket(raw)
254 }
255}