lite_sync/request_response/
common.rs

1/// Core types and utilities for request-response channels
2/// 
3/// 请求-响应通道的核心类型和工具
4use std::fmt;
5
6/// Error type for channel operations
7/// 
8/// Channel 操作的错误类型
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum ChannelError {
11    /// The remote side has been closed
12    /// 
13    /// 对端已关闭
14    Closed,
15    
16    /// The channel is full (for bounded channels)
17    /// 
18    /// 通道已满(用于有界通道)
19    Full,
20}
21
22impl fmt::Display for ChannelError {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            ChannelError::Closed => write!(f, "channel closed"),
26            ChannelError::Full => write!(f, "channel full"),
27        }
28    }
29}
30
31impl std::error::Error for ChannelError {}
32
33/// State constants for request-response state machine
34/// 
35/// 请求-响应状态机的状态常量
36pub mod state {
37    /// Channel is idle, ready to accept new request
38    /// 
39    /// 通道空闲,准备接受新请求
40    pub const IDLE: u8 = 0;
41    
42    /// Request sent, waiting for response
43    /// 
44    /// 请求已发送,等待响应
45    pub const WAITING_RESPONSE: u8 = 1;
46    
47    /// Response is ready to be received
48    /// 
49    /// 响应已就绪,可以接收
50    pub const RESPONSE_READY: u8 = 2;
51}