pub trait TimerConfig: Send + 'static {
type Storage: DerefMut<Target = dyn Handler<Instant>> + Send + 'static;
// Required method
fn wrap(handler: impl Handler<Instant> + 'static) -> Self::Storage;
}Expand description
Configuration trait for generic timer code.
ZST annotation type that bundles the handler storage type with a
wrapping function. Library code parameterized over C: TimerConfig
can schedule, cancel, and wrap handlers without knowing the concrete
storage strategy.
§Example
ⓘ
use std::time::Instant;
use nexus_rt::timer::{BoxedTimers, TimerConfig};
use nexus_rt::{Handler, World};
use nexus_timer::Wheel;
fn schedule_heartbeat<C: TimerConfig>(
world: &mut World,
handler: impl Handler<Instant> + 'static,
deadline: Instant,
) {
world.resource_mut::<Wheel<C::Storage>>()
.schedule_forget(deadline, C::wrap(handler));
}Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl TimerConfig for BoxedTimers
impl TimerConfig for BoxedTimers
Source§impl TimerConfig for FlexTimers
Available on crate feature smartptr only.
impl TimerConfig for FlexTimers
Available on crate feature
smartptr only.