kestrel_timer/
error.rs

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