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