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    /// Batch operation failed: handles and tasks length mismatch
30    /// 
31    /// 批量操作失败:handles 和 tasks 长度不匹配
32    BatchLengthMismatch {
33        handles_len: usize,
34        tasks_len: usize,
35    },
36}
37
38impl fmt::Display for TimerError {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        match self {
41            TimerError::InvalidSlotCount { slot_count, reason } => {
42                write!(f, "Invalid slot count {}: {} (无效的槽位数 {}: {})", slot_count, reason, slot_count, reason)
43            }
44            TimerError::InvalidConfiguration { field, reason } => {
45                write!(f, "Configuration validation failed ({}): {} (配置验证失败 ({}): {})", field, reason, field, reason)
46            }
47            TimerError::RegisterFailed => {
48                write!(f, "Registration failed: internal channel is full or closed (注册失败: 内部通道已满或已关闭)")
49            }
50            TimerError::BatchLengthMismatch { handles_len, tasks_len } => {
51                write!(f, "Batch operation failed: handles length ({}) does not match tasks length ({}) (批量操作失败: handles 长度 ({}) 与 tasks 长度 ({}) 不匹配)", 
52                    handles_len, tasks_len, handles_len, tasks_len)
53            }
54        }
55    }
56}
57
58impl std::error::Error for TimerError {}
59