1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::fmt;
/// Timer Error Type
///
/// 定时器错误类型
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TimerError {
/// Invalid slot count (must be a power of 2 and greater than 0)
///
/// 无效的槽位数 (必须是 2 的幂且大于 0)
InvalidSlotCount {
slot_count: usize,
reason: &'static str,
},
/// Configuration validation failed
///
/// 配置验证失败
InvalidConfiguration { field: String, reason: String },
/// Registration failed, internal channel is full or closed
///
/// 注册失败,内部通道已满或已关闭
RegisterFailed,
/// Batch operation failed: handles and tasks length mismatch
///
/// 批量操作失败:handles 和 tasks 长度不匹配
BatchLengthMismatch {
handles_len: usize,
tasks_len: usize,
},
}
impl fmt::Display for TimerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TimerError::InvalidSlotCount { slot_count, reason } => {
write!(
f,
"Invalid slot count {}: {} (无效的槽位数 {}: {})",
slot_count, reason, slot_count, reason
)
}
TimerError::InvalidConfiguration { field, reason } => {
write!(
f,
"Configuration validation failed ({}): {} (配置验证失败 ({}): {})",
field, reason, field, reason
)
}
TimerError::RegisterFailed => {
write!(
f,
"Registration failed: internal channel is full or closed (注册失败: 内部通道已满或已关闭)"
)
}
TimerError::BatchLengthMismatch {
handles_len,
tasks_len,
} => {
write!(
f,
"Batch operation failed: handles length ({}) does not match tasks length ({}) (批量操作失败: handles 长度 ({}) 与 tasks 长度 ({}) 不匹配)",
handles_len, tasks_len, handles_len, tasks_len
)
}
}
}
}
impl std::error::Error for TimerError {}