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
@@ -98,6 +100,7 @@ impl OwnedFd {
98100 }
99101
100102 #[ cfg( target_arch = "wasm32" ) ]
103+ #[ stable( feature = "io_safety" , since = "1.63.0" ) ]
101104 pub fn try_clone ( & self ) -> crate :: io:: Result < Self > {
102105 Err ( crate :: io:: const_io_error!(
103106 crate :: io:: ErrorKind :: Unsupported ,
@@ -106,23 +109,23 @@ impl OwnedFd {
106109 }
107110}
108111
109- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
112+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
110113impl AsRawFd for BorrowedFd < ' _ > {
111114 #[ inline]
112115 fn as_raw_fd ( & self ) -> RawFd {
113116 self . fd
114117 }
115118}
116119
117- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
120+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
118121impl AsRawFd for OwnedFd {
119122 #[ inline]
120123 fn as_raw_fd ( & self ) -> RawFd {
121124 self . fd
122125 }
123126}
124127
125- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
128+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
126129impl IntoRawFd for OwnedFd {
127130 #[ inline]
128131 fn into_raw_fd ( self ) -> RawFd {
@@ -132,7 +135,7 @@ impl IntoRawFd for OwnedFd {
132135 }
133136}
134137
135- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
138+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
136139impl FromRawFd for OwnedFd {
137140 /// Constructs a new instance of `Self` from the given raw file descriptor.
138141 ///
@@ -148,7 +151,7 @@ impl FromRawFd for OwnedFd {
148151 }
149152}
150153
151- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
154+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
152155impl Drop for OwnedFd {
153156 #[ inline]
154157 fn drop ( & mut self ) {
@@ -163,14 +166,14 @@ impl Drop for OwnedFd {
163166 }
164167}
165168
166- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
169+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
167170impl fmt:: Debug for BorrowedFd < ' _ > {
168171 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
169172 f. debug_struct ( "BorrowedFd" ) . field ( "fd" , & self . fd ) . finish ( )
170173 }
171174}
172175
173- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
176+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
174177impl fmt:: Debug for OwnedFd {
175178 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
176179 f. debug_struct ( "OwnedFd" ) . field ( "fd" , & self . fd ) . finish ( )
@@ -182,14 +185,13 @@ impl fmt::Debug for OwnedFd {
182185/// This is only available on unix platforms and must be imported in order to
183186/// call the method. Windows platforms have a corresponding `AsHandle` and
184187/// `AsSocket` set of traits.
185- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
188+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
186189pub trait AsFd {
187190 /// Borrows the file descriptor.
188191 ///
189192 /// # Example
190193 ///
191194 /// ```rust,no_run
192- /// # #![feature(io_safety)]
193195 /// use std::fs::File;
194196 /// # use std::io;
195197 /// # #[cfg(target_os = "wasi")]
@@ -202,35 +204,35 @@ pub trait AsFd {
202204 /// let borrowed_fd: BorrowedFd<'_> = f.as_fd();
203205 /// # Ok::<(), io::Error>(())
204206 /// ```
205- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
207+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
206208 fn as_fd ( & self ) -> BorrowedFd < ' _ > ;
207209}
208210
209- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
211+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
210212impl < T : AsFd > AsFd for & T {
211213 #[ inline]
212214 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
213215 T :: as_fd ( self )
214216 }
215217}
216218
217- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
219+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
218220impl < T : AsFd > AsFd for & mut T {
219221 #[ inline]
220222 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
221223 T :: as_fd ( self )
222224 }
223225}
224226
225- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
227+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
226228impl AsFd for BorrowedFd < ' _ > {
227229 #[ inline]
228230 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
229231 * self
230232 }
231233}
232234
233- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
235+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
234236impl AsFd for OwnedFd {
235237 #[ inline]
236238 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
@@ -241,47 +243,47 @@ impl AsFd for OwnedFd {
241243 }
242244}
243245
244- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
246+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
245247impl AsFd for fs:: File {
246248 #[ inline]
247249 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
248250 self . as_inner ( ) . as_fd ( )
249251 }
250252}
251253
252- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
254+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
253255impl From < fs:: File > for OwnedFd {
254256 #[ inline]
255257 fn from ( file : fs:: File ) -> OwnedFd {
256258 file. into_inner ( ) . into_inner ( ) . into_inner ( )
257259 }
258260}
259261
260- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
262+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
261263impl From < OwnedFd > for fs:: File {
262264 #[ inline]
263265 fn from ( owned_fd : OwnedFd ) -> Self {
264266 Self :: from_inner ( FromInner :: from_inner ( FromInner :: from_inner ( owned_fd) ) )
265267 }
266268}
267269
268- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
270+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
269271impl AsFd for crate :: net:: TcpStream {
270272 #[ inline]
271273 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
272274 self . as_inner ( ) . socket ( ) . as_fd ( )
273275 }
274276}
275277
276- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
278+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
277279impl From < crate :: net:: TcpStream > for OwnedFd {
278280 #[ inline]
279281 fn from ( tcp_stream : crate :: net:: TcpStream ) -> OwnedFd {
280282 tcp_stream. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
281283 }
282284}
283285
284- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
286+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
285287impl From < OwnedFd > for crate :: net:: TcpStream {
286288 #[ inline]
287289 fn from ( owned_fd : OwnedFd ) -> Self {
@@ -291,23 +293,23 @@ impl From<OwnedFd> for crate::net::TcpStream {
291293 }
292294}
293295
294- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
296+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
295297impl AsFd for crate :: net:: TcpListener {
296298 #[ inline]
297299 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
298300 self . as_inner ( ) . socket ( ) . as_fd ( )
299301 }
300302}
301303
302- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
304+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
303305impl From < crate :: net:: TcpListener > for OwnedFd {
304306 #[ inline]
305307 fn from ( tcp_listener : crate :: net:: TcpListener ) -> OwnedFd {
306308 tcp_listener. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
307309 }
308310}
309311
310- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
312+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
311313impl From < OwnedFd > for crate :: net:: TcpListener {
312314 #[ inline]
313315 fn from ( owned_fd : OwnedFd ) -> Self {
@@ -317,23 +319,23 @@ impl From<OwnedFd> for crate::net::TcpListener {
317319 }
318320}
319321
320- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
322+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
321323impl AsFd for crate :: net:: UdpSocket {
322324 #[ inline]
323325 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
324326 self . as_inner ( ) . socket ( ) . as_fd ( )
325327 }
326328}
327329
328- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
330+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
329331impl From < crate :: net:: UdpSocket > for OwnedFd {
330332 #[ inline]
331333 fn from ( udp_socket : crate :: net:: UdpSocket ) -> OwnedFd {
332334 udp_socket. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
333335 }
334336}
335337
336- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
338+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
337339impl From < OwnedFd > for crate :: net:: UdpSocket {
338340 #[ inline]
339341 fn from ( owned_fd : OwnedFd ) -> Self {
0 commit comments