Skip to main content

TimerConfig

Trait TimerConfig 

Source
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§

Source

type Storage: DerefMut<Target = dyn Handler<Instant>> + Send + 'static

The handler storage type (e.g. Box<dyn Handler<Instant>>).

Required Methods§

Source

fn wrap(handler: impl Handler<Instant> + 'static) -> Self::Storage

Wrap a concrete handler into the storage type.

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

Source§

impl TimerConfig for FlexTimers

Available on crate feature smartptr only.
Source§

impl TimerConfig for InlineTimers

Available on crate feature smartptr only.