1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum TimerError {
8 InvalidSlotCount {
12 slot_count: usize,
13 reason: &'static str,
14 },
15
16 InvalidConfiguration { field: String, reason: String },
20
21 RegisterFailed,
25
26 Shutdown,
30
31 WrongWheel,
35
36 BatchLengthMismatch {
40 handles_len: usize,
41 tasks_len: usize,
42 },
43}
44
45impl fmt::Display for TimerError {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 match self {
48 TimerError::InvalidSlotCount { slot_count, reason } => {
49 write!(
50 f,
51 "Invalid slot count {}: {} (无效的槽位数 {}: {})",
52 slot_count, reason, slot_count, reason
53 )
54 }
55 TimerError::InvalidConfiguration { field, reason } => {
56 write!(
57 f,
58 "Configuration validation failed ({}): {} (配置验证失败 ({}): {})",
59 field, reason, field, reason
60 )
61 }
62 TimerError::RegisterFailed => {
63 write!(
64 f,
65 "Registration failed: internal channel is full or closed (注册失败: 内部通道已满或已关闭)"
66 )
67 }
68 TimerError::Shutdown => {
69 write!(f, "Timer wheel has been shut down (时间轮已关闭)")
70 }
71 TimerError::WrongWheel => {
72 write!(
73 f,
74 "Task belongs to a different timing wheel (任务属于另一个时间轮)"
75 )
76 }
77 TimerError::BatchLengthMismatch {
78 handles_len,
79 tasks_len,
80 } => {
81 write!(
82 f,
83 "Batch operation failed: handles length ({}) does not match tasks length ({}) (批量操作失败: handles 长度 ({}) 与 tasks 长度 ({}) 不匹配)",
84 handles_len, tasks_len, handles_len, tasks_len
85 )
86 }
87 }
88 }
89}
90
91impl std::error::Error for TimerError {}