@@ -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 {
@@ -235,8 +239,12 @@ impl fmt::Debug for Context<'_> {
235239/// of `*waker = new_waker.clone()`, as the former will avoid cloning the waker
236240/// unnecessarily if the two wakers [wake the same task](Self::will_wake).
237241///
242+ /// Constructing a `Waker` from a [`RawWaker`] is unsafe.
243+ /// Implementing the [`Wake`] trait is a safe alternative that requires memory allocation.
244+ ///
238245/// [`Future::poll()`]: core::future::Future::poll
239246/// [`Poll::Pending`]: core::task::Poll::Pending
247+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
240248#[ cfg_attr( not( doc) , repr( transparent) ) ] // work around https://github.com/rust-lang/rust/issues/66401
241249#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
242250pub struct Waker {
@@ -318,9 +326,15 @@ impl Waker {
318326
319327 /// Creates a new `Waker` from [`RawWaker`].
320328 ///
329+ /// # Safety
330+ ///
321331 /// The behavior of the returned `Waker` is undefined if the contract defined
322332 /// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
323- /// Therefore this method is unsafe.
333+ ///
334+ /// (Authors wishing to avoid unsafe code may implement the [`Wake`] trait instead, at the
335+ /// cost of a required heap allocation.)
336+ ///
337+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
324338 #[ inline]
325339 #[ must_use]
326340 #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
0 commit comments