subms_timer_wheel/error.rs
1//! Typed error surface for the wheel family.
2
3use std::fmt;
4
5/// Every way a schedule can be refused. `schedule` clamps instead of
6/// returning these; `try_schedule` surfaces them.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum TimerError {
9 /// The delay is past what the wheel can represent. On the base wheel the
10 /// ceiling is `num_slots * u32::MAX` (the rounds counter is a `u32`); on
11 /// the hierarchical wheel it is the coarsest level's span.
12 DelayTooLong { delay: u64, max: u64 },
13}
14
15impl fmt::Display for TimerError {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 match self {
18 TimerError::DelayTooLong { delay, max } => {
19 write!(
20 f,
21 "delay {delay} ticks exceeds the wheel capacity of {max} ticks"
22 )
23 }
24 }
25 }
26}
27
28impl std::error::Error for TimerError {}
29
30#[cfg(test)]
31#[path = "error_tests.rs"]
32mod tests;