pub trait TimerRuntime {
type TimerId;
// Required methods
fn set_timer(&mut self, id: Self::TimerId, duration: Duration);
fn kill_timer(&mut self, id: Self::TimerId);
}Expand description
A runtime that can set and kill timers.
The state machine produces TimerCommands in its Response.
The runtime implements this trait to translate those commands into
actual platform timer operations.
§Invariant: Set resets an existing timer
Implementations must ensure that calling set_timer
with an ID that already has an active timer replaces that timer rather
than creating a second concurrent timer for the same ID. The new timer
starts counting from the moment set_timer is called.
§Platform examples
| Platform | set_timer | kill_timer |
|---|---|---|
| Windows | SetTimer() (reuses the same nIDEvent) | KillTimer() |
| Linux | timerfd_settime() (overwrites existing armed state) | timerfd_settime(0) |
| macOS | CFRunLoopTimerSetNextFireDate() (adjusts fire date) | invalidate the CFRunLoopTimerRef |
| Test | record to Vec | record to Vec |
Required Associated Types§
Required Methods§
Sourcefn set_timer(&mut self, id: Self::TimerId, duration: Duration)
fn set_timer(&mut self, id: Self::TimerId, duration: Duration)
Start or restart a timer.
If a timer with the same ID is already active, it must be reset to the new duration — only one timer per ID may be active at a time.
Sourcefn kill_timer(&mut self, id: Self::TimerId)
fn kill_timer(&mut self, id: Self::TimerId)
Stop an active timer. No-op if the timer is not active.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".