1
- #![ unstable( feature = "futures_api" ,
2
- reason = "futures in libcore are unstable" ,
3
- issue = "50547" ) ]
1
+ #![ stable( feature = "futures_api" , since = "1.36.0" ) ]
4
2
5
3
use crate :: fmt;
6
4
use crate :: marker:: { PhantomData , Unpin } ;
@@ -13,6 +11,7 @@ use crate::marker::{PhantomData, Unpin};
13
11
/// It consists of a data pointer and a [virtual function pointer table (vtable)][vtable] that
14
12
/// customizes the behavior of the `RawWaker`.
15
13
#[ derive( PartialEq , Debug ) ]
14
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
16
15
pub struct RawWaker {
17
16
/// A data pointer, which can be used to store arbitrary data as required
18
17
/// by the executor. This could be e.g. a type-erased pointer to an `Arc`
@@ -37,9 +36,7 @@ impl RawWaker {
37
36
/// from a `RawWaker`. For each operation on the `Waker`, the associated
38
37
/// function in the `vtable` of the underlying `RawWaker` will be called.
39
38
#[ rustc_promotable]
40
- #[ unstable( feature = "futures_api" ,
41
- reason = "futures in libcore are unstable" ,
42
- issue = "50547" ) ]
39
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
43
40
pub const fn new ( data : * const ( ) , vtable : & ' static RawWakerVTable ) -> RawWaker {
44
41
RawWaker {
45
42
data,
@@ -58,6 +55,7 @@ impl RawWaker {
58
55
/// pointer of a properly constructed [`RawWaker`] object from inside the
59
56
/// [`RawWaker`] implementation. Calling one of the contained functions using
60
57
/// any other `data` pointer will cause undefined behavior.
58
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
61
59
#[ derive( PartialEq , Copy , Clone , Debug ) ]
62
60
pub struct RawWakerVTable {
63
61
/// This function will be called when the [`RawWaker`] gets cloned, e.g. when
@@ -131,9 +129,14 @@ impl RawWakerVTable {
131
129
/// resources that are associated with this instance of a [`RawWaker`] and
132
130
/// associated task.
133
131
#[ rustc_promotable]
134
- #[ unstable( feature = "futures_api" ,
135
- reason = "futures in libcore are unstable" ,
136
- issue = "50547" ) ]
132
+ #[ cfg_attr( stage0, unstable( feature = "futures_api_const_fn_ptr" , issue = "50547" ) ) ]
133
+ #[ cfg_attr( not( stage0) , stable( feature = "futures_api" , since = "1.36.0" ) ) ]
134
+ // `rustc_allow_const_fn_ptr` is a hack that should not be used anywhere else
135
+ // without first consulting with T-Lang.
136
+ //
137
+ // FIXME: remove whenever we have a stable way to accept fn pointers from const fn
138
+ // (see https://github.com/rust-rfcs/const-eval/issues/19#issuecomment-472799062)
139
+ #[ cfg_attr( not( stage0) , rustc_allow_const_fn_ptr) ]
137
140
pub const fn new (
138
141
clone : unsafe fn ( * const ( ) ) -> RawWaker ,
139
142
wake : unsafe fn ( * const ( ) ) ,
@@ -153,6 +156,7 @@ impl RawWakerVTable {
153
156
///
154
157
/// Currently, `Context` only serves to provide access to a `&Waker`
155
158
/// which can be used to wake the current task.
159
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
156
160
pub struct Context < ' a > {
157
161
waker : & ' a Waker ,
158
162
// Ensure we future-proof against variance changes by forcing
@@ -164,6 +168,7 @@ pub struct Context<'a> {
164
168
165
169
impl < ' a > Context < ' a > {
166
170
/// Create a new `Context` from a `&Waker`.
171
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
167
172
#[ inline]
168
173
pub fn from_waker ( waker : & ' a Waker ) -> Self {
169
174
Context {
@@ -173,12 +178,14 @@ impl<'a> Context<'a> {
173
178
}
174
179
175
180
/// Returns a reference to the `Waker` for the current task.
181
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
176
182
#[ inline]
177
183
pub fn waker ( & self ) -> & ' a Waker {
178
184
& self . waker
179
185
}
180
186
}
181
187
188
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
182
189
impl fmt:: Debug for Context < ' _ > {
183
190
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
184
191
f. debug_struct ( "Context" )
@@ -195,17 +202,22 @@ impl fmt::Debug for Context<'_> {
195
202
///
196
203
/// Implements [`Clone`], [`Send`], and [`Sync`].
197
204
#[ repr( transparent) ]
205
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
198
206
pub struct Waker {
199
207
waker : RawWaker ,
200
208
}
201
209
210
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
202
211
impl Unpin for Waker { }
212
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
203
213
unsafe impl Send for Waker { }
214
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
204
215
unsafe impl Sync for Waker { }
205
216
206
217
impl Waker {
207
218
/// Wake up the task associated with this `Waker`.
208
219
#[ inline]
220
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
209
221
pub fn wake ( self ) {
210
222
// The actual wakeup call is delegated through a virtual function call
211
223
// to the implementation which is defined by the executor.
@@ -227,6 +239,7 @@ impl Waker {
227
239
/// where an owned `Waker` is available. This method should be preferred to
228
240
/// calling `waker.clone().wake()`.
229
241
#[ inline]
242
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
230
243
pub fn wake_by_ref ( & self ) {
231
244
// The actual wakeup call is delegated through a virtual function call
232
245
// to the implementation which is defined by the executor.
@@ -243,6 +256,7 @@ impl Waker {
243
256
///
244
257
/// This function is primarily used for optimization purposes.
245
258
#[ inline]
259
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
246
260
pub fn will_wake ( & self , other : & Waker ) -> bool {
247
261
self . waker == other. waker
248
262
}
@@ -253,13 +267,15 @@ impl Waker {
253
267
/// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
254
268
/// Therefore this method is unsafe.
255
269
#[ inline]
270
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
256
271
pub unsafe fn from_raw ( waker : RawWaker ) -> Waker {
257
272
Waker {
258
273
waker,
259
274
}
260
275
}
261
276
}
262
277
278
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
263
279
impl Clone for Waker {
264
280
#[ inline]
265
281
fn clone ( & self ) -> Self {
@@ -272,6 +288,7 @@ impl Clone for Waker {
272
288
}
273
289
}
274
290
291
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
275
292
impl Drop for Waker {
276
293
#[ inline]
277
294
fn drop ( & mut self ) {
@@ -282,6 +299,7 @@ impl Drop for Waker {
282
299
}
283
300
}
284
301
302
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
285
303
impl fmt:: Debug for Waker {
286
304
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
287
305
let vtable_ptr = self . waker . vtable as * const RawWakerVTable ;
0 commit comments