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    ChannelClosed,
14}
15
16impl fmt::Display for TimerError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            TimerError::InvalidSlotCount { slot_count, reason } => {
20                write!(f, "无效的槽位数量 {}: {}", slot_count, reason)
21            }
22            TimerError::ChannelClosed => {
23                write!(f, "内部通信通道已关闭")
24            }
25        }
26    }
27}
28
29impl std::error::Error for TimerError {}
30