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 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 {}