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 {
20 field: String,
21 reason: String,
22 },
23
24 RegisterFailed,
28
29 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