@@ -7,10 +7,14 @@ use crate::ptr;
77/// A `RawWaker` allows the implementor of a task executor to create a [`Waker`]
88/// which provides customized wakeup behavior.
99///
10- /// [vtable]: https://en.wikipedia.org/wiki/Virtual_method_table
11- ///
1210/// It consists of a data pointer and a [virtual function pointer table (vtable)][vtable]
1311/// that customizes the behavior of the `RawWaker`.
12+ ///
13+ /// `RawWaker`s are unsafe to use.
14+ /// Implementing the [`Wake`] trait is a safe alternative that requires memory allocation.
15+ ///
16+ /// [vtable]: https://en.wikipedia.org/wiki/Virtual_method_table
17+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
1418#[ derive( PartialEq , Debug ) ]
1519#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
1620pub struct RawWaker {
@@ -231,8 +235,12 @@ impl fmt::Debug for Context<'_> {
231235/// this might be done to wake a future when a blocking function call completes on another
232236/// thread.
233237///
238+ /// Constructing a `Waker` from a [`RawWaker`] is unsafe.
239+ /// Implementing the [`Wake`] trait is a safe alternative that requires memory allocation.
240+ ///
234241/// [`Future::poll()`]: core::future::Future::poll
235242/// [`Poll::Pending`]: core::task::Poll::Pending
243+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
236244#[ cfg_attr( not( doc) , repr( transparent) ) ] // work around https://github.com/rust-lang/rust/issues/66401
237245#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
238246pub struct Waker {
@@ -312,9 +320,15 @@ impl Waker {
312320
313321 /// Creates a new `Waker` from [`RawWaker`].
314322 ///
323+ /// # Safety
324+ ///
315325 /// The behavior of the returned `Waker` is undefined if the contract defined
316326 /// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
317- /// Therefore this method is unsafe.
327+ ///
328+ /// (Authors wishing to avoid unsafe code may implement the [`Wake`] trait instead, at the
329+ /// cost of a required heap allocation.)
330+ ///
331+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
318332 #[ inline]
319333 #[ must_use]
320334 #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
0 commit comments