1
1
//! Owned and borrowed Unix-like file descriptors.
2
2
3
- #![ unstable ( feature = "io_safety" , issue = "87074 " ) ]
3
+ #![ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
4
4
#![ deny( unsafe_op_in_unsafe_fn) ]
5
5
6
6
use super :: raw:: { AsRawFd , FromRawFd , IntoRawFd , RawFd } ;
@@ -33,7 +33,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
33
33
// because c_int is 32 bits.
34
34
#[ rustc_layout_scalar_valid_range_end( 0xFF_FF_FF_FE ) ]
35
35
#[ rustc_nonnull_optimization_guaranteed]
36
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
36
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
37
37
pub struct BorrowedFd < ' fd > {
38
38
fd : RawFd ,
39
39
_phantom : PhantomData < & ' fd OwnedFd > ,
@@ -54,7 +54,7 @@ pub struct BorrowedFd<'fd> {
54
54
// because c_int is 32 bits.
55
55
#[ rustc_layout_scalar_valid_range_end( 0xFF_FF_FF_FE ) ]
56
56
#[ rustc_nonnull_optimization_guaranteed]
57
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
57
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
58
58
pub struct OwnedFd {
59
59
fd : RawFd ,
60
60
}
@@ -67,7 +67,8 @@ impl BorrowedFd<'_> {
67
67
/// The resource pointed to by `fd` must remain open for the duration of
68
68
/// the returned `BorrowedFd`, and it must not have the value `-1`.
69
69
#[ 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" ) ]
71
72
pub const unsafe fn borrow_raw ( fd : RawFd ) -> Self {
72
73
assert ! ( fd != u32 :: MAX as RawFd ) ;
73
74
// 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 {
79
80
/// Creates a new `OwnedFd` instance that shares the same underlying file handle
80
81
/// as the existing `OwnedFd` instance.
81
82
#[ cfg( not( target_arch = "wasm32" ) ) ]
83
+ #[ stable( feature = "io_safety" , since = "1.63.0" ) ]
82
84
pub fn try_clone ( & self ) -> crate :: io:: Result < Self > {
83
85
// We want to atomically duplicate this file descriptor and set the
84
86
// CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
@@ -106,23 +108,23 @@ impl OwnedFd {
106
108
}
107
109
}
108
110
109
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
111
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
110
112
impl AsRawFd for BorrowedFd < ' _ > {
111
113
#[ inline]
112
114
fn as_raw_fd ( & self ) -> RawFd {
113
115
self . fd
114
116
}
115
117
}
116
118
117
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
119
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
118
120
impl AsRawFd for OwnedFd {
119
121
#[ inline]
120
122
fn as_raw_fd ( & self ) -> RawFd {
121
123
self . fd
122
124
}
123
125
}
124
126
125
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
127
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
126
128
impl IntoRawFd for OwnedFd {
127
129
#[ inline]
128
130
fn into_raw_fd ( self ) -> RawFd {
@@ -132,7 +134,7 @@ impl IntoRawFd for OwnedFd {
132
134
}
133
135
}
134
136
135
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
137
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
136
138
impl FromRawFd for OwnedFd {
137
139
/// Constructs a new instance of `Self` from the given raw file descriptor.
138
140
///
@@ -148,7 +150,7 @@ impl FromRawFd for OwnedFd {
148
150
}
149
151
}
150
152
151
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
153
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
152
154
impl Drop for OwnedFd {
153
155
#[ inline]
154
156
fn drop ( & mut self ) {
@@ -163,14 +165,14 @@ impl Drop for OwnedFd {
163
165
}
164
166
}
165
167
166
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
168
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
167
169
impl fmt:: Debug for BorrowedFd < ' _ > {
168
170
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
169
171
f. debug_struct ( "BorrowedFd" ) . field ( "fd" , & self . fd ) . finish ( )
170
172
}
171
173
}
172
174
173
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
175
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
174
176
impl fmt:: Debug for OwnedFd {
175
177
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
176
178
f. debug_struct ( "OwnedFd" ) . field ( "fd" , & self . fd ) . finish ( )
@@ -182,14 +184,13 @@ impl fmt::Debug for OwnedFd {
182
184
/// This is only available on unix platforms and must be imported in order to
183
185
/// call the method. Windows platforms have a corresponding `AsHandle` and
184
186
/// `AsSocket` set of traits.
185
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
187
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
186
188
pub trait AsFd {
187
189
/// Borrows the file descriptor.
188
190
///
189
191
/// # Example
190
192
///
191
193
/// ```rust,no_run
192
- /// # #![feature(io_safety)]
193
194
/// use std::fs::File;
194
195
/// # use std::io;
195
196
/// # #[cfg(target_os = "wasi")]
@@ -202,35 +203,35 @@ pub trait AsFd {
202
203
/// let borrowed_fd: BorrowedFd<'_> = f.as_fd();
203
204
/// # Ok::<(), io::Error>(())
204
205
/// ```
205
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
206
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
206
207
fn as_fd ( & self ) -> BorrowedFd < ' _ > ;
207
208
}
208
209
209
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
210
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
210
211
impl < T : AsFd > AsFd for & T {
211
212
#[ inline]
212
213
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
213
214
T :: as_fd ( self )
214
215
}
215
216
}
216
217
217
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
218
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
218
219
impl < T : AsFd > AsFd for & mut T {
219
220
#[ inline]
220
221
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
221
222
T :: as_fd ( self )
222
223
}
223
224
}
224
225
225
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
226
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
226
227
impl AsFd for BorrowedFd < ' _ > {
227
228
#[ inline]
228
229
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
229
230
* self
230
231
}
231
232
}
232
233
233
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
234
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
234
235
impl AsFd for OwnedFd {
235
236
#[ inline]
236
237
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
@@ -241,47 +242,47 @@ impl AsFd for OwnedFd {
241
242
}
242
243
}
243
244
244
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
245
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
245
246
impl AsFd for fs:: File {
246
247
#[ inline]
247
248
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
248
249
self . as_inner ( ) . as_fd ( )
249
250
}
250
251
}
251
252
252
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
253
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
253
254
impl From < fs:: File > for OwnedFd {
254
255
#[ inline]
255
256
fn from ( file : fs:: File ) -> OwnedFd {
256
257
file. into_inner ( ) . into_inner ( ) . into_inner ( )
257
258
}
258
259
}
259
260
260
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
261
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
261
262
impl From < OwnedFd > for fs:: File {
262
263
#[ inline]
263
264
fn from ( owned_fd : OwnedFd ) -> Self {
264
265
Self :: from_inner ( FromInner :: from_inner ( FromInner :: from_inner ( owned_fd) ) )
265
266
}
266
267
}
267
268
268
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
269
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
269
270
impl AsFd for crate :: net:: TcpStream {
270
271
#[ inline]
271
272
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
272
273
self . as_inner ( ) . socket ( ) . as_fd ( )
273
274
}
274
275
}
275
276
276
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
277
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
277
278
impl From < crate :: net:: TcpStream > for OwnedFd {
278
279
#[ inline]
279
280
fn from ( tcp_stream : crate :: net:: TcpStream ) -> OwnedFd {
280
281
tcp_stream. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
281
282
}
282
283
}
283
284
284
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
285
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
285
286
impl From < OwnedFd > for crate :: net:: TcpStream {
286
287
#[ inline]
287
288
fn from ( owned_fd : OwnedFd ) -> Self {
@@ -291,23 +292,23 @@ impl From<OwnedFd> for crate::net::TcpStream {
291
292
}
292
293
}
293
294
294
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
295
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
295
296
impl AsFd for crate :: net:: TcpListener {
296
297
#[ inline]
297
298
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
298
299
self . as_inner ( ) . socket ( ) . as_fd ( )
299
300
}
300
301
}
301
302
302
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
303
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
303
304
impl From < crate :: net:: TcpListener > for OwnedFd {
304
305
#[ inline]
305
306
fn from ( tcp_listener : crate :: net:: TcpListener ) -> OwnedFd {
306
307
tcp_listener. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
307
308
}
308
309
}
309
310
310
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
311
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
311
312
impl From < OwnedFd > for crate :: net:: TcpListener {
312
313
#[ inline]
313
314
fn from ( owned_fd : OwnedFd ) -> Self {
@@ -317,23 +318,23 @@ impl From<OwnedFd> for crate::net::TcpListener {
317
318
}
318
319
}
319
320
320
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
321
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
321
322
impl AsFd for crate :: net:: UdpSocket {
322
323
#[ inline]
323
324
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
324
325
self . as_inner ( ) . socket ( ) . as_fd ( )
325
326
}
326
327
}
327
328
328
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
329
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
329
330
impl From < crate :: net:: UdpSocket > for OwnedFd {
330
331
#[ inline]
331
332
fn from ( udp_socket : crate :: net:: UdpSocket ) -> OwnedFd {
332
333
udp_socket. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
333
334
}
334
335
}
335
336
336
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
337
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
337
338
impl From < OwnedFd > for crate :: net:: UdpSocket {
338
339
#[ inline]
339
340
fn from ( owned_fd : OwnedFd ) -> Self {
0 commit comments