# Easy Waker API

**URL:** <https://internals.rust-lang.org/t/easy-waker-api/11726>\
**Category:** libs\
**Created:** [January 30, 2020, 12:44pm UTC](https://internals.rust-lang.org/t/easy-waker-api/11726 "2020-01-30T12:44:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![withoutboats](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/withoutboats/32/4560_2.png) [@withoutboats](https://internals.rust-lang.org/u/withoutboats)\
**Post date:** [January 30, 2020, 12:44pm UTC](https://internals.rust-lang.org/t/easy-waker-api/11726/1 "2020-01-30T12:44:44Z")

</div>

It was always our intent to add these APIs to std:

```rust
trait Wake {
    fn wake(self: Arc<Self>);

    fn wake_by_ref(self: &Arc<Self>) {
        self.clone().wake()
    }
}

impl Waker {
    pub fn new<W: Wake>(waker: Arc<W>) -> Waker { ... }
}

```

However, this is incompatible with the current core/alloc/std set-up: Wake must be in alloc or std, because it references Arc, but Waker::new must be defined in core, and it references Arc. This is an example of where using cargo features and conditional compilation would improve std's APIs.

But it occurred to me this week that this impl _could_ be defined in alloc:

```rust
impl<W: Wake> From<Arc<W>> for Waker {
    fn from(waker: Arc<W>) -> Waker { ... }
}

```

I am not driven to spearhead this at the moment, but someone could add a task module to alloc which contains the `Wake` trait and this impl, and then for the common case of wakers which are arcs, the user could write:

```rust
struct MyWaker {
    ...
}

impl Wake for MyWaker {
    fn wake(self: Arc<Self>) { ... }
}

Waker::from(Arc::new(MyWaker { ... }))

```

This API is not only convenient for this common case it is also 100% safe (unlike the current RawWaker based API).

cc @anon19897381

---

<div class="post-metadata">

**Author:** ![withoutboats](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/withoutboats/32/4560_2.png) [@withoutboats](https://internals.rust-lang.org/u/withoutboats)\
**Post date:** [April 29, 2020, 12:44pm UTC](https://internals.rust-lang.org/t/easy-waker-api/11726/2 "2020-04-29T12:44:51Z")

</div>

Closed on April 29, 2020, 12:44pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
