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
@@ -98,6 +100,7 @@ impl OwnedFd {
98
100
}
99
101
100
102
#[ cfg( target_arch = "wasm32" ) ]
103
+ #[ stable( feature = "io_safety" , since = "1.63.0" ) ]
101
104
pub fn try_clone ( & self ) -> crate :: io:: Result < Self > {
102
105
Err ( crate :: io:: const_io_error!(
103
106
crate :: io:: ErrorKind :: Unsupported ,
@@ -106,23 +109,23 @@ impl OwnedFd {
106
109
}
107
110
}
108
111
109
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
112
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
110
113
impl AsRawFd for BorrowedFd < ' _ > {
111
114
#[ inline]
112
115
fn as_raw_fd ( & self ) -> RawFd {
113
116
self . fd
114
117
}
115
118
}
116
119
117
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
120
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
118
121
impl AsRawFd for OwnedFd {
119
122
#[ inline]
120
123
fn as_raw_fd ( & self ) -> RawFd {
121
124
self . fd
122
125
}
123
126
}
124
127
125
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
128
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
126
129
impl IntoRawFd for OwnedFd {
127
130
#[ inline]
128
131
fn into_raw_fd ( self ) -> RawFd {
@@ -132,7 +135,7 @@ impl IntoRawFd for OwnedFd {
132
135
}
133
136
}
134
137
135
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
138
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
136
139
impl FromRawFd for OwnedFd {
137
140
/// Constructs a new instance of `Self` from the given raw file descriptor.
138
141
///
@@ -148,7 +151,7 @@ impl FromRawFd for OwnedFd {
148
151
}
149
152
}
150
153
151
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
154
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
152
155
impl Drop for OwnedFd {
153
156
#[ inline]
154
157
fn drop ( & mut self ) {
@@ -163,14 +166,14 @@ impl Drop for OwnedFd {
163
166
}
164
167
}
165
168
166
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
169
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
167
170
impl fmt:: Debug for BorrowedFd < ' _ > {
168
171
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
169
172
f. debug_struct ( "BorrowedFd" ) . field ( "fd" , & self . fd ) . finish ( )
170
173
}
171
174
}
172
175
173
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
176
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
174
177
impl fmt:: Debug for OwnedFd {
175
178
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
176
179
f. debug_struct ( "OwnedFd" ) . field ( "fd" , & self . fd ) . finish ( )
@@ -182,14 +185,13 @@ impl fmt::Debug for OwnedFd {
182
185
/// This is only available on unix platforms and must be imported in order to
183
186
/// call the method. Windows platforms have a corresponding `AsHandle` and
184
187
/// `AsSocket` set of traits.
185
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
188
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
186
189
pub trait AsFd {
187
190
/// Borrows the file descriptor.
188
191
///
189
192
/// # Example
190
193
///
191
194
/// ```rust,no_run
192
- /// # #![feature(io_safety)]
193
195
/// use std::fs::File;
194
196
/// # use std::io;
195
197
/// # #[cfg(target_os = "wasi")]
@@ -202,35 +204,35 @@ pub trait AsFd {
202
204
/// let borrowed_fd: BorrowedFd<'_> = f.as_fd();
203
205
/// # Ok::<(), io::Error>(())
204
206
/// ```
205
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
207
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
206
208
fn as_fd ( & self ) -> BorrowedFd < ' _ > ;
207
209
}
208
210
209
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
211
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
210
212
impl < T : AsFd > AsFd for & T {
211
213
#[ inline]
212
214
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
213
215
T :: as_fd ( self )
214
216
}
215
217
}
216
218
217
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
219
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
218
220
impl < T : AsFd > AsFd for & mut T {
219
221
#[ inline]
220
222
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
221
223
T :: as_fd ( self )
222
224
}
223
225
}
224
226
225
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
227
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
226
228
impl AsFd for BorrowedFd < ' _ > {
227
229
#[ inline]
228
230
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
229
231
* self
230
232
}
231
233
}
232
234
233
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
235
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
234
236
impl AsFd for OwnedFd {
235
237
#[ inline]
236
238
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
@@ -241,47 +243,47 @@ impl AsFd for OwnedFd {
241
243
}
242
244
}
243
245
244
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
246
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
245
247
impl AsFd for fs:: File {
246
248
#[ inline]
247
249
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
248
250
self . as_inner ( ) . as_fd ( )
249
251
}
250
252
}
251
253
252
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
254
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
253
255
impl From < fs:: File > for OwnedFd {
254
256
#[ inline]
255
257
fn from ( file : fs:: File ) -> OwnedFd {
256
258
file. into_inner ( ) . into_inner ( ) . into_inner ( )
257
259
}
258
260
}
259
261
260
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
262
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
261
263
impl From < OwnedFd > for fs:: File {
262
264
#[ inline]
263
265
fn from ( owned_fd : OwnedFd ) -> Self {
264
266
Self :: from_inner ( FromInner :: from_inner ( FromInner :: from_inner ( owned_fd) ) )
265
267
}
266
268
}
267
269
268
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
270
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
269
271
impl AsFd for crate :: net:: TcpStream {
270
272
#[ inline]
271
273
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
272
274
self . as_inner ( ) . socket ( ) . as_fd ( )
273
275
}
274
276
}
275
277
276
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
278
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
277
279
impl From < crate :: net:: TcpStream > for OwnedFd {
278
280
#[ inline]
279
281
fn from ( tcp_stream : crate :: net:: TcpStream ) -> OwnedFd {
280
282
tcp_stream. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
281
283
}
282
284
}
283
285
284
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
286
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
285
287
impl From < OwnedFd > for crate :: net:: TcpStream {
286
288
#[ inline]
287
289
fn from ( owned_fd : OwnedFd ) -> Self {
@@ -291,23 +293,23 @@ impl From<OwnedFd> for crate::net::TcpStream {
291
293
}
292
294
}
293
295
294
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
296
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
295
297
impl AsFd for crate :: net:: TcpListener {
296
298
#[ inline]
297
299
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
298
300
self . as_inner ( ) . socket ( ) . as_fd ( )
299
301
}
300
302
}
301
303
302
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
304
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
303
305
impl From < crate :: net:: TcpListener > for OwnedFd {
304
306
#[ inline]
305
307
fn from ( tcp_listener : crate :: net:: TcpListener ) -> OwnedFd {
306
308
tcp_listener. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
307
309
}
308
310
}
309
311
310
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
312
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
311
313
impl From < OwnedFd > for crate :: net:: TcpListener {
312
314
#[ inline]
313
315
fn from ( owned_fd : OwnedFd ) -> Self {
@@ -317,23 +319,23 @@ impl From<OwnedFd> for crate::net::TcpListener {
317
319
}
318
320
}
319
321
320
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
322
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
321
323
impl AsFd for crate :: net:: UdpSocket {
322
324
#[ inline]
323
325
fn as_fd ( & self ) -> BorrowedFd < ' _ > {
324
326
self . as_inner ( ) . socket ( ) . as_fd ( )
325
327
}
326
328
}
327
329
328
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
330
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
329
331
impl From < crate :: net:: UdpSocket > for OwnedFd {
330
332
#[ inline]
331
333
fn from ( udp_socket : crate :: net:: UdpSocket ) -> OwnedFd {
332
334
udp_socket. into_inner ( ) . into_socket ( ) . into_inner ( ) . into_inner ( ) . into ( )
333
335
}
334
336
}
335
337
336
- #[ unstable ( feature = "io_safety" , issue = "87074 " ) ]
338
+ #[ stable ( feature = "io_safety" , since = "1.63.0 " ) ]
337
339
impl From < OwnedFd > for crate :: net:: UdpSocket {
338
340
#[ inline]
339
341
fn from ( owned_fd : OwnedFd ) -> Self {
0 commit comments