1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::task::Waker;
pub struct Context<'a> {
waker: Option<&'a Waker>,
}
impl<'a> From<std::task::Context<'a>> for Context<'a> {
fn from(cx: std::task::Context<'a>) -> Self {
Self::from_waker(cx.waker())
}
}
impl<'a> From<&std::task::Context<'a>> for Context<'a> {
fn from(cx: &std::task::Context<'a>) -> Self {
Self::from_waker(cx.waker())
}
}
impl<'a> From<&mut std::task::Context<'a>> for Context<'a> {
fn from(cx: &mut std::task::Context<'a>) -> Self {
Self::from_waker(cx.waker())
}
}
impl<'a> Context<'a> {
pub fn from_waker(waker: &'a Waker) -> Self {
Context { waker: Some(waker) }
}
pub fn empty() -> Self {
Self { waker: None }
}
pub fn waker(&self) -> Option<&'a Waker> {
self.waker
}
}
impl std::fmt::Debug for Context<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Context")
.field("waker", &self.waker)
.finish()
}
}