1- #![ unstable( feature = "futures_api" ,
2- reason = "futures in libcore are unstable" ,
3- issue = "50547" ) ]
1+ #![ stable( feature = "futures_api" , since = "1.36.0" ) ]
42
53use crate :: fmt;
64use crate :: marker:: { PhantomData , Unpin } ;
@@ -13,6 +11,7 @@ use crate::marker::{PhantomData, Unpin};
1311/// It consists of a data pointer and a [virtual function pointer table (vtable)][vtable] that
1412/// customizes the behavior of the `RawWaker`.
1513#[ derive( PartialEq , Debug ) ]
14+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
1615pub struct RawWaker {
1716 /// A data pointer, which can be used to store arbitrary data as required
1817 /// by the executor. This could be e.g. a type-erased pointer to an `Arc`
@@ -37,9 +36,7 @@ impl RawWaker {
3736 /// from a `RawWaker`. For each operation on the `Waker`, the associated
3837 /// function in the `vtable` of the underlying `RawWaker` will be called.
3938 #[ 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" ) ]
4340 pub const fn new ( data : * const ( ) , vtable : & ' static RawWakerVTable ) -> RawWaker {
4441 RawWaker {
4542 data,
@@ -58,6 +55,7 @@ impl RawWaker {
5855/// pointer of a properly constructed [`RawWaker`] object from inside the
5956/// [`RawWaker`] implementation. Calling one of the contained functions using
6057/// any other `data` pointer will cause undefined behavior.
58+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
6159#[ derive( PartialEq , Copy , Clone , Debug ) ]
6260pub struct RawWakerVTable {
6361 /// This function will be called when the [`RawWaker`] gets cloned, e.g. when
@@ -131,9 +129,14 @@ impl RawWakerVTable {
131129 /// resources that are associated with this instance of a [`RawWaker`] and
132130 /// associated task.
133131 #[ 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) ]
137140 pub const fn new (
138141 clone : unsafe fn ( * const ( ) ) -> RawWaker ,
139142 wake : unsafe fn ( * const ( ) ) ,
@@ -153,6 +156,7 @@ impl RawWakerVTable {
153156///
154157/// Currently, `Context` only serves to provide access to a `&Waker`
155158/// which can be used to wake the current task.
159+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
156160pub struct Context < ' a > {
157161 waker : & ' a Waker ,
158162 // Ensure we future-proof against variance changes by forcing
@@ -164,6 +168,7 @@ pub struct Context<'a> {
164168
165169impl < ' a > Context < ' a > {
166170 /// Create a new `Context` from a `&Waker`.
171+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
167172 #[ inline]
168173 pub fn from_waker ( waker : & ' a Waker ) -> Self {
169174 Context {
@@ -173,12 +178,14 @@ impl<'a> Context<'a> {
173178 }
174179
175180 /// Returns a reference to the `Waker` for the current task.
181+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
176182 #[ inline]
177183 pub fn waker ( & self ) -> & ' a Waker {
178184 & self . waker
179185 }
180186}
181187
188+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
182189impl fmt:: Debug for Context < ' _ > {
183190 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
184191 f. debug_struct ( "Context" )
@@ -195,17 +202,22 @@ impl fmt::Debug for Context<'_> {
195202///
196203/// Implements [`Clone`], [`Send`], and [`Sync`].
197204#[ repr( transparent) ]
205+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
198206pub struct Waker {
199207 waker : RawWaker ,
200208}
201209
210+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
202211impl Unpin for Waker { }
212+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
203213unsafe impl Send for Waker { }
214+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
204215unsafe impl Sync for Waker { }
205216
206217impl Waker {
207218 /// Wake up the task associated with this `Waker`.
208219 #[ inline]
220+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
209221 pub fn wake ( self ) {
210222 // The actual wakeup call is delegated through a virtual function call
211223 // to the implementation which is defined by the executor.
@@ -227,6 +239,7 @@ impl Waker {
227239 /// where an owned `Waker` is available. This method should be preferred to
228240 /// calling `waker.clone().wake()`.
229241 #[ inline]
242+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
230243 pub fn wake_by_ref ( & self ) {
231244 // The actual wakeup call is delegated through a virtual function call
232245 // to the implementation which is defined by the executor.
@@ -243,6 +256,7 @@ impl Waker {
243256 ///
244257 /// This function is primarily used for optimization purposes.
245258 #[ inline]
259+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
246260 pub fn will_wake ( & self , other : & Waker ) -> bool {
247261 self . waker == other. waker
248262 }
@@ -253,13 +267,15 @@ impl Waker {
253267 /// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
254268 /// Therefore this method is unsafe.
255269 #[ inline]
270+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
256271 pub unsafe fn from_raw ( waker : RawWaker ) -> Waker {
257272 Waker {
258273 waker,
259274 }
260275 }
261276}
262277
278+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
263279impl Clone for Waker {
264280 #[ inline]
265281 fn clone ( & self ) -> Self {
@@ -272,6 +288,7 @@ impl Clone for Waker {
272288 }
273289}
274290
291+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
275292impl Drop for Waker {
276293 #[ inline]
277294 fn drop ( & mut self ) {
@@ -282,6 +299,7 @@ impl Drop for Waker {
282299 }
283300}
284301
302+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
285303impl fmt:: Debug for Waker {
286304 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
287305 let vtable_ptr = self . waker . vtable as * const RawWakerVTable ;
0 commit comments