use std::{fmt, rc::Rc};
use crate::time::driver::ClockTime;
#[derive(Clone)]
pub(crate) struct Handle {
time_source: ClockTime,
inner: Rc<super::Inner>,
}
impl Handle {
pub(super) fn new(inner: Rc<super::Inner>) -> Self {
let time_source = inner.state.borrow_mut().time_source.clone();
Handle { time_source, inner }
}
pub(super) fn time_source(&self) -> &ClockTime {
&self.time_source
}
pub(super) fn get(&self) -> &super::Inner {
&self.inner
}
}
impl Handle {
pub(crate) fn current() -> Self {
crate::runtime::CURRENT.with(|c| {
c.time_handle.clone().expect(
"unable to get time handle, maybe you have not enable_timer on creating runtime?",
)
})
}
}
impl fmt::Debug for Handle {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Handle")
}
}