use crate::{AnyTimerCallback, Node, Time, Timer};
pub trait IntoNodeTimerRepeatingCallback<Args>: 'static + Send {
fn into_node_timer_repeating_callback(self) -> AnyTimerCallback<Node>;
}
impl<Func> IntoNodeTimerRepeatingCallback<()> for Func
where
Func: FnMut() + 'static + Send,
{
fn into_node_timer_repeating_callback(mut self) -> AnyTimerCallback<Node> {
AnyTimerCallback::Repeating(Box::new(move |_, _| self())).into()
}
}
impl<Func> IntoNodeTimerRepeatingCallback<Timer> for Func
where
Func: FnMut(&Timer) + 'static + Send,
{
fn into_node_timer_repeating_callback(mut self) -> AnyTimerCallback<Node> {
AnyTimerCallback::Repeating(Box::new(move |_, t| self(t))).into()
}
}
impl<Func> IntoNodeTimerRepeatingCallback<Time> for Func
where
Func: FnMut(Time) + 'static + Send,
{
fn into_node_timer_repeating_callback(mut self) -> AnyTimerCallback<Node> {
AnyTimerCallback::Repeating(Box::new(move |_, t| self(t.handle.clock.now()))).into()
}
}
pub trait IntoNodeTimerOneshotCallback<Args>: 'static + Send {
fn into_node_timer_oneshot_callback(self) -> AnyTimerCallback<Node>;
}
impl<Func> IntoNodeTimerOneshotCallback<()> for Func
where
Func: FnOnce() + 'static + Send,
{
fn into_node_timer_oneshot_callback(self) -> AnyTimerCallback<Node> {
AnyTimerCallback::OneShot(Box::new(move |_, _| self())).into()
}
}
impl<Func> IntoNodeTimerOneshotCallback<Timer> for Func
where
Func: FnOnce(&Timer) + 'static + Send,
{
fn into_node_timer_oneshot_callback(self) -> AnyTimerCallback<Node> {
AnyTimerCallback::OneShot(Box::new(move |_, t| self(t))).into()
}
}
impl<Func> IntoNodeTimerOneshotCallback<Time> for Func
where
Func: FnOnce(Time) + 'static + Send,
{
fn into_node_timer_oneshot_callback(self) -> AnyTimerCallback<Node> {
AnyTimerCallback::OneShot(Box::new(move |_, t| self(t.handle.clock.now()))).into()
}
}