kestrel_protocol_timer/
error.rs

1use std::fmt;
2
3/// 定时器错误类型
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum TimerError {
6    /// 槽位数量无效(必须是 2 的幂次方且大于 0)
7    InvalidSlotCount { 
8        slot_count: usize,
9        reason: &'static str,
10    },
11    
12    /// 配置验证失败
13    InvalidConfiguration {
14        field: String,
15        reason: String,
16    },
17    
18    /// 内部通信通道已关闭
19    ChannelClosed,
20}
21
22impl fmt::Display for TimerError {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            TimerError::InvalidSlotCount { slot_count, reason } => {
26                write!(f, "无效的槽位数量 {}: {}", slot_count, reason)
27            }
28            TimerError::InvalidConfiguration { field, reason } => {
29                write!(f, "配置验证失败 ({}): {}", field, reason)
30            }
31            TimerError::ChannelClosed => {
32                write!(f, "内部通信通道已关闭")
33            }
34        }
35    }
36}
37
38impl std::error::Error for TimerError {}
39