diff --git a/src/liballoc/task.rs b/src/liballoc/task.rs index a64d5d7a63ba0..949357dcd2d55 100644 --- a/src/liballoc/task.rs +++ b/src/liballoc/task.rs @@ -51,6 +51,26 @@ impl From> for RawWaker { } } +/// Convert a closure into a waker. +/// +/// # Examples +/// +/// ``` +/// use std::sync::Arc; +/// use std::task::Waker; +/// +/// let waker = Waker::from(Arc::new(|| { +/// // wake called +/// })); +/// waker.wake(); +/// ``` +#[unstable(feature = "wake_from_fn", issue = "none")] +impl Wake for F { + fn wake(self: Arc) { + (self)() + } +} + // NB: This private function for constructing a RawWaker is used, rather than // inlining this into the `From> for RawWaker` impl, to ensure that // the safety of `From> for Waker` does not depend on the correct