@@ -39,7 +39,7 @@ impl RawWaker {
39
39
/// thread safe type such as an `[Arc]<T: Send + Sync>`
40
40
/// when used to construct a [`Waker`]. This restriction is lifted when
41
41
/// constructing a [`LocalWaker`], which allows using types that do not implement
42
- /// <code>[Send] + [Sync]</code> like `[Rc]<T: !Send + !Sync >`.
42
+ /// <code>[Send] + [Sync]</code> like `[Rc]<T>`.
43
43
///
44
44
/// The `vtable` customizes the behavior of a `Waker` which gets created
45
45
/// from a `RawWaker`. For each operation on the `Waker`, the associated
@@ -240,16 +240,6 @@ impl<'a> Context<'a> {
240
240
}
241
241
242
242
/// Returns a reference to the [`Waker`] for the current task.
243
- ///
244
- /// Note that if the waker does not need to be sent across threads, it
245
- /// is preferable to call `local_waker`, which is more portable and
246
- /// potentially more efficient.
247
- ///
248
- /// # Panics
249
- /// This function will panic if no `Waker` was set on the context. This happens if
250
- /// the executor does not support working with thread safe wakers. An alternative
251
- /// may be to call [`.local_waker()`](Context::local_waker) instead. For a fallible
252
- /// version of this function see [`.try_waker()`](Context::try_waker).
253
243
#[ inline]
254
244
#[ must_use]
255
245
#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
@@ -396,7 +386,7 @@ impl<'a> ContextBuilder<'a> {
396
386
impl < ' a > From < & mut Context < ' a > > for ContextBuilder < ' a > {
397
387
#[ inline]
398
388
fn from ( value : & mut Context < ' a > ) -> Self {
399
- let Context { waker, local_waker, .. } = * value;
389
+ let Context { waker, local_waker, _marker , _marker2 } = * value;
400
390
ContextBuilder { waker, local_waker }
401
391
}
402
392
}
@@ -415,8 +405,7 @@ impl<'a> From<&mut Context<'a>> for ContextBuilder<'a> {
415
405
/// Implements [`Clone`], [`Send`], and [`Sync`]; therefore, a waker may be invoked
416
406
/// from any thread, including ones not in any way managed by the executor. For example,
417
407
/// this might be done to wake a future when a blocking function call completes on another
418
- /// thread. If the waker does not need to be moved across threads, it is better to use
419
- /// [`LocalWaker`], which the executor may use to skip unnecessary memory synchronization.
408
+ /// thread.
420
409
///
421
410
/// Note that it is preferable to use `waker.clone_from(&new_waker)` instead
422
411
/// of `*waker = new_waker.clone()`, as the former will avoid cloning the waker
@@ -656,19 +645,6 @@ pub struct LocalWaker {
656
645
impl Unpin for LocalWaker { }
657
646
658
647
impl LocalWaker {
659
- /// Creates a new `LocalWaker` from [`RawWaker`].
660
- ///
661
- /// The behavior of the returned `LocalWaker` is undefined if the contract defined
662
- /// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
663
- /// Therefore this method is unsafe.
664
- #[ inline]
665
- #[ must_use]
666
- #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
667
- #[ rustc_const_unstable( feature = "const_waker" , issue = "102012" ) ]
668
- pub const unsafe fn from_raw ( waker : RawWaker ) -> LocalWaker {
669
- Self { waker }
670
- }
671
-
672
648
/// Wake up the task associated with this `LocalWaker`.
673
649
///
674
650
/// As long as the executor keeps running and the task is not finished, it is
@@ -703,6 +679,37 @@ impl LocalWaker {
703
679
unsafe { ( wake) ( data) } ;
704
680
}
705
681
682
+ /// Wake up the task associated with this `LocalWaker` without consuming the `LocalWaker`.
683
+ ///
684
+ /// This is similar to [`wake()`](Self::wake), but may be slightly less efficient in
685
+ /// the case where an owned `Waker` is available. This method should be preferred to
686
+ /// calling `waker.clone().wake()`.
687
+ #[ inline]
688
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
689
+ pub fn wake_by_ref ( & self ) {
690
+ // The actual wakeup call is delegated through a virtual function call
691
+ // to the implementation which is defined by the executor.
692
+
693
+ // SAFETY: see `wake`
694
+ unsafe { ( self . waker . vtable . wake_by_ref ) ( self . waker . data ) }
695
+ }
696
+
697
+ /// Returns `true` if this `LocalWaker` and another `LocalWaker` would awake the same task.
698
+ ///
699
+ /// This function works on a best-effort basis, and may return false even
700
+ /// when the `Waker`s would awaken the same task. However, if this function
701
+ /// returns `true`, it is guaranteed that the `Waker`s will awaken the same task.
702
+ ///
703
+ /// This function is primarily used for optimization purposes — for example,
704
+ /// this type's [`clone_from`](Self::clone_from) implementation uses it to
705
+ /// avoid cloning the waker when they would wake the same task anyway.
706
+ #[ inline]
707
+ #[ must_use]
708
+ #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
709
+ pub fn will_wake ( & self , other : & LocalWaker ) -> bool {
710
+ self . waker == other. waker
711
+ }
712
+
706
713
/// Creates a new `LocalWaker` that does nothing when `wake` is called.
707
714
///
708
715
/// This is mostly useful for writing tests that need a [`Context`] to poll
@@ -733,43 +740,25 @@ impl LocalWaker {
733
740
WAKER
734
741
}
735
742
736
- /// Get a reference to the underlying [`RawWaker`].
737
- #[ inline]
738
- #[ must_use]
739
- #[ unstable( feature = "waker_getters" , issue = "96992" ) ]
740
- pub fn as_raw ( & self ) -> & RawWaker {
741
- & self . waker
742
- }
743
-
744
- /// Returns `true` if this `LocalWaker` and another `LocalWaker` would awake the same task.
745
- ///
746
- /// This function works on a best-effort basis, and may return false even
747
- /// when the `Waker`s would awaken the same task. However, if this function
748
- /// returns `true`, it is guaranteed that the `Waker`s will awaken the same task.
743
+ /// Creates a new `LocalWaker` from [`RawWaker`].
749
744
///
750
- /// This function is primarily used for optimization purposes — for example,
751
- /// this type 's [`clone_from`](Self::clone_from) implementation uses it to
752
- /// avoid cloning the waker when they would wake the same task anyway .
745
+ /// The behavior of the returned `LocalWaker` is undefined if the contract defined
746
+ /// in [`RawWaker`] 's and [`RawWakerVTable`]'s documentation is not upheld.
747
+ /// Therefore this method is unsafe .
753
748
#[ inline]
754
749
#[ must_use]
755
750
#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
756
- pub fn will_wake ( & self , other : & LocalWaker ) -> bool {
757
- self . waker == other. waker
751
+ #[ rustc_const_unstable( feature = "const_waker" , issue = "102012" ) ]
752
+ pub const unsafe fn from_raw ( waker : RawWaker ) -> LocalWaker {
753
+ Self { waker }
758
754
}
759
755
760
- /// Wake up the task associated with this `LocalWaker` without consuming the `LocalWaker`.
761
- ///
762
- /// This is similar to [`wake()`](Self::wake), but may be slightly less efficient in
763
- /// the case where an owned `Waker` is available. This method should be preferred to
764
- /// calling `waker.clone().wake()`.
756
+ /// Get a reference to the underlying [`RawWaker`].
765
757
#[ inline]
766
- #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
767
- pub fn wake_by_ref ( & self ) {
768
- // The actual wakeup call is delegated through a virtual function call
769
- // to the implementation which is defined by the executor.
770
-
771
- // SAFETY: see `wake`
772
- unsafe { ( self . waker . vtable . wake_by_ref ) ( self . waker . data ) }
758
+ #[ must_use]
759
+ #[ unstable( feature = "waker_getters" , issue = "96992" ) ]
760
+ pub fn as_raw ( & self ) -> & RawWaker {
761
+ & self . waker
773
762
}
774
763
}
775
764
#[ unstable( feature = "local_waker" , issue = "118959" ) ]
0 commit comments