11//! Owned and borrowed Unix-like file descriptors.
22
3- #![ unstable ( feature = "io_safety" , issue = "87074 " ) ]
3+ #![ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
44#![ deny( unsafe_op_in_unsafe_fn) ]
55
66use super :: raw:: { AsRawFd , FromRawFd , IntoRawFd , RawFd } ;
@@ -33,7 +33,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
3333// because c_int is 32 bits.
3434#[ rustc_layout_scalar_valid_range_end( 0xFF_FF_FF_FE ) ]
3535#[ rustc_nonnull_optimization_guaranteed]
36- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
36+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
3737pub struct BorrowedFd < ' fd > {
3838 fd : RawFd ,
3939 _phantom : PhantomData < & ' fd OwnedFd > ,
@@ -54,7 +54,7 @@ pub struct BorrowedFd<'fd> {
5454// because c_int is 32 bits.
5555#[ rustc_layout_scalar_valid_range_end( 0xFF_FF_FF_FE ) ]
5656#[ rustc_nonnull_optimization_guaranteed]
57- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
57+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
5858pub struct OwnedFd {
5959 fd : RawFd ,
6060}
@@ -67,7 +67,8 @@ impl BorrowedFd<'_> {
6767 /// The resource pointed to by `fd` must remain open for the duration of
6868 /// the returned `BorrowedFd`, and it must not have the value `-1`.
6969 #[ inline]
70- #[ unstable( feature = "io_safety" , issue = "87074" ) ]
70+ #[ rustc_const_stable( feature = "io_safety" , since = "1.63.0" ) ]
71+ #[ stable( feature = "io_safety" , since = "1.63.0" ) ]
7172 pub const unsafe fn borrow_raw ( fd : RawFd ) -> Self {
7273 assert ! ( fd != u32 :: MAX as RawFd ) ;
7374 // SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
@@ -79,6 +80,7 @@ impl OwnedFd {
7980 /// Creates a new `OwnedFd` instance that shares the same underlying file handle
8081 /// as the existing `OwnedFd` instance.
8182 #[ cfg( not( target_arch = "wasm32" ) ) ]
83+ #[ stable( feature = "io_safety" , since = "1.63.0" ) ]
8284 pub fn try_clone ( & self ) -> crate :: io:: Result < Self > {
8385 // We want to atomically duplicate this file descriptor and set the
8486 // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
@@ -106,23 +108,23 @@ impl OwnedFd {
106108 }
107109}
108110
109- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
111+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
110112impl AsRawFd for BorrowedFd < ' _ > {
111113 #[ inline]
112114 fn as_raw_fd ( & self ) -> RawFd {
113115 self . fd
114116 }
115117}
116118
117- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
119+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
118120impl AsRawFd for OwnedFd {
119121 #[ inline]
120122 fn as_raw_fd ( & self ) -> RawFd {
121123 self . fd
122124 }
123125}
124126
125- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
127+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
126128impl IntoRawFd for OwnedFd {
127129 #[ inline]
128130 fn into_raw_fd ( self ) -> RawFd {
@@ -132,7 +134,7 @@ impl IntoRawFd for OwnedFd {
132134 }
133135}
134136
135- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
137+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
136138impl FromRawFd for OwnedFd {
137139 /// Constructs a new instance of `Self` from the given raw file descriptor.
138140 ///
@@ -148,7 +150,7 @@ impl FromRawFd for OwnedFd {
148150 }
149151}
150152
151- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
153+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
152154impl Drop for OwnedFd {
153155 #[ inline]
154156 fn drop ( & mut self ) {
@@ -163,14 +165,14 @@ impl Drop for OwnedFd {
163165 }
164166}
165167
166- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
168+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
167169impl fmt:: Debug for BorrowedFd < ' _ > {
168170 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
169171 f. debug_struct ( "BorrowedFd" ) . field ( "fd" , & self . fd ) . finish ( )
170172 }
171173}
172174
173- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
175+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
174176impl fmt:: Debug for OwnedFd {
175177 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
176178 f. debug_struct ( "OwnedFd" ) . field ( "fd" , & self . fd ) . finish ( )
@@ -182,14 +184,13 @@ impl fmt::Debug for OwnedFd {
182184/// This is only available on unix platforms and must be imported in order to
183185/// call the method. Windows platforms have a corresponding `AsHandle` and
184186/// `AsSocket` set of traits.
185- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
187+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
186188pub trait AsFd {
187189 /// Borrows the file descriptor.
188190 ///
189191 /// # Example
190192 ///
191193 /// ```rust,no_run
192- /// # #![feature(io_safety)]
193194 /// use std::fs::File;
194195 /// # use std::io;
195196 /// # #[cfg(target_os = "wasi")]
@@ -202,35 +203,35 @@ pub trait AsFd {
202203 /// let borrowed_fd: BorrowedFd<'_> = f.as_fd();
203204 /// # Ok::<(), io::Error>(())
204205 /// ```
205- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
206+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
206207 fn as_fd ( & self ) -> BorrowedFd < ' _ > ;
207208}
208209
209- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
210+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
210211impl < T : AsFd > AsFd for & T {
211212 #[ inline]
212213 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
213214 T :: as_fd ( self )
214215 }
215216}
216217
217- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
218+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
218219impl < T : AsFd > AsFd for & mut T {
219220 #[ inline]
220221 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
221222 T :: as_fd ( self )
222223 }
223224}
224225
225- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
226+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
226227impl AsFd for BorrowedFd < ' _ > {
227228 #[ inline]
228229 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
229230 * self
230231 }
231232}
232233
233- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
234+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
234235impl AsFd for OwnedFd {
235236 #[ inline]
236237 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
@@ -241,47 +242,47 @@ impl AsFd for OwnedFd {
241242 }
242243}
243244
244- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
245+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
245246impl AsFd for fs:: File {
246247 #[ inline]
247248 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
248249 self . as_inner ( ) . as_fd ( )
249250 }
250251}
251252
252- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
253+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
253254impl From < fs:: File > for OwnedFd {
254255 #[ inline]
255256 fn from ( file : fs:: File ) -> OwnedFd {
256257 file. into_inner ( ) . into_inner ( ) . into_inner ( )
257258 }
258259}
259260
260- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
261+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
261262impl From < OwnedFd > for fs:: File {
262263 #[ inline]
263264 fn from ( owned_fd : OwnedFd ) -> Self {
264265 Self :: from_inner ( FromInner :: from_inner ( FromInner :: from_inner ( owned_fd) ) )
265266 }
266267}
267268
268- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
269+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
269270impl AsFd for crate :: net:: TcpStream {
270271 #[ inline]
271272 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
272273 self . as_inner ( ) . socket ( ) . as_fd ( )
273274 }
274275}
275276
276- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
277+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
277278impl From < crate :: net:: TcpStream > for OwnedFd {
278279 #[ inline]
279280 fn from ( tcp_stream : crate :: net:: TcpStream ) -> OwnedFd {
280281 tcp_stream. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
281282 }
282283}
283284
284- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
285+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
285286impl From < OwnedFd > for crate :: net:: TcpStream {
286287 #[ inline]
287288 fn from ( owned_fd : OwnedFd ) -> Self {
@@ -291,23 +292,23 @@ impl From<OwnedFd> for crate::net::TcpStream {
291292 }
292293}
293294
294- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
295+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
295296impl AsFd for crate :: net:: TcpListener {
296297 #[ inline]
297298 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
298299 self . as_inner ( ) . socket ( ) . as_fd ( )
299300 }
300301}
301302
302- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
303+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
303304impl From < crate :: net:: TcpListener > for OwnedFd {
304305 #[ inline]
305306 fn from ( tcp_listener : crate :: net:: TcpListener ) -> OwnedFd {
306307 tcp_listener. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
307308 }
308309}
309310
310- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
311+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
311312impl From < OwnedFd > for crate :: net:: TcpListener {
312313 #[ inline]
313314 fn from ( owned_fd : OwnedFd ) -> Self {
@@ -317,23 +318,23 @@ impl From<OwnedFd> for crate::net::TcpListener {
317318 }
318319}
319320
320- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
321+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
321322impl AsFd for crate :: net:: UdpSocket {
322323 #[ inline]
323324 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
324325 self . as_inner ( ) . socket ( ) . as_fd ( )
325326 }
326327}
327328
328- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
329+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
329330impl From < crate :: net:: UdpSocket > for OwnedFd {
330331 #[ inline]
331332 fn from ( udp_socket : crate :: net:: UdpSocket ) -> OwnedFd {
332333 udp_socket. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
333334 }
334335}
335336
336- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
337+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
337338impl From < OwnedFd > for crate :: net:: UdpSocket {
338339 #[ inline]
339340 fn from ( owned_fd : OwnedFd ) -> Self {
0 commit comments