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()
}
}