use crate::{AnyTimerCallback, Time, TimerState, WorkScope};
use std::sync::Arc;
pub trait IntoWorkerTimerRepeatingCallback<Scope: WorkScope, Args>: 'static + Send {
fn into_worker_timer_repeating_callback(self) -> AnyTimerCallback<Scope>;
}
impl<Scope: WorkScope, Func> IntoWorkerTimerRepeatingCallback<Scope, ()> for Func
where
Func: FnMut() + 'static + Send,
{
fn into_worker_timer_repeating_callback(mut self) -> AnyTimerCallback<Scope> {
AnyTimerCallback::Repeating(Box::new(move |_, _| self())).into()
}
}
impl<Scope: WorkScope, Func> IntoWorkerTimerRepeatingCallback<Scope, (Scope::Payload,)> for Func
where
Func: FnMut(&mut Scope::Payload) + 'static + Send,
{
fn into_worker_timer_repeating_callback(mut self) -> AnyTimerCallback<Scope> {
AnyTimerCallback::Repeating(Box::new(move |payload, _| self(payload))).into()
}
}
impl<Scope: WorkScope, Func>
IntoWorkerTimerRepeatingCallback<Scope, (Scope::Payload, Arc<TimerState<Scope>>)> for Func
where
Func: FnMut(&mut Scope::Payload, &Arc<TimerState<Scope>>) + 'static + Send,
{
fn into_worker_timer_repeating_callback(self) -> AnyTimerCallback<Scope> {
AnyTimerCallback::Repeating(Box::new(self)).into()
}
}
impl<Scope: WorkScope, Func> IntoWorkerTimerRepeatingCallback<Scope, (Scope::Payload, Time)>
for Func
where
Func: FnMut(&mut Scope::Payload, Time) + 'static + Send,
{
fn into_worker_timer_repeating_callback(mut self) -> AnyTimerCallback<Scope> {
AnyTimerCallback::Repeating(Box::new(move |payload, t| {
self(payload, t.handle.clock.now())
}))
.into()
}
}
pub trait IntoWorkerTimerOneshotCallback<Scope: WorkScope, Args>: 'static + Send {
fn into_worker_timer_oneshot_callback(self) -> AnyTimerCallback<Scope>;
}
impl<Scope: WorkScope, Func> IntoWorkerTimerOneshotCallback<Scope, ()> for Func
where
Func: FnOnce() + 'static + Send,
{
fn into_worker_timer_oneshot_callback(self) -> AnyTimerCallback<Scope> {
AnyTimerCallback::OneShot(Box::new(move |_, _| self())).into()
}
}
impl<Scope: WorkScope, Func> IntoWorkerTimerOneshotCallback<Scope, (Scope::Payload,)> for Func
where
Func: FnOnce(&mut Scope::Payload) + 'static + Send,
{
fn into_worker_timer_oneshot_callback(self) -> AnyTimerCallback<Scope> {
AnyTimerCallback::OneShot(Box::new(move |payload, _| self(payload))).into()
}
}
impl<Scope: WorkScope, Func>
IntoWorkerTimerOneshotCallback<Scope, (Scope::Payload, Arc<TimerState<Scope>>)> for Func
where
Func: FnOnce(&mut Scope::Payload, &Arc<TimerState<Scope>>) + 'static + Send,
{
fn into_worker_timer_oneshot_callback(self) -> AnyTimerCallback<Scope> {
AnyTimerCallback::OneShot(Box::new(self)).into()
}
}
impl<Scope: WorkScope, Func> IntoWorkerTimerOneshotCallback<Scope, (Scope::Payload, Time)> for Func
where
Func: FnMut(&mut Scope::Payload, Time) + 'static + Send,
{
fn into_worker_timer_oneshot_callback(mut self) -> AnyTimerCallback<Scope> {
AnyTimerCallback::OneShot(Box::new(move |payload, t| {
self(payload, t.handle.clock.now())
}))
.into()
}
}