kestrel_timer/
error.rs

1use std::fmt;
2
3/// 定时器错误类型 (Timer Error Type)
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum TimerError {
6    /// 槽位数量无效(必须是 2 的幂次方且大于 0)
7    /// Invalid slot count (must be a power of 2 and greater than 0)
8    InvalidSlotCount { 
9        slot_count: usize,
10        reason: &'static str,
11    },
12    
13    /// 配置验证失败 (Configuration validation failed)
14    InvalidConfiguration {
15        field: String,
16        reason: String,
17    },
18    
19    /// 注册失败(内部通道已满或已关闭)
20    /// Registration failed (internal channel is full or closed)
21    RegisterFailed,
22}
23
24impl fmt::Display for TimerError {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            TimerError::InvalidSlotCount { slot_count, reason } => {
28                write!(f, "Invalid slot count {}: {}", slot_count, reason)
29            }
30            TimerError::InvalidConfiguration { field, reason } => {
31                write!(f, "Configuration validation failed ({}): {}", field, reason)
32            }
33            TimerError::RegisterFailed => {
34                write!(f, "Registration failed: internal channel is full or closed")
35            }
36        }
37    }
38}
39
40impl std::error::Error for TimerError {}
41