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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Thrift protocol handling for asynchronous services.
//!
//! This module provides traits and types for implementing Thrift handlers
//! that can be used with asynchronous services. It defines a common interface
//! for processing Thrift requests and generating responses, with support for
//! context-aware handling.
//!
//! # Key Components
//!
//! - [`ThriftHandler`]: A trait for implementing Thrift request handlers.
//! - [`ThriftRequest`]: A type alias for Thrift requests using TTHeader protocol.
//! - [`ThriftResponse`]: A type alias for Thrift responses using TTHeader protocol.
//! - [`ThriftBody`]: A type alias for the payload of Thrift requests and responses.
use Future;
use TTHeaderPayload;
use Service;
use crateSealedT;
/// Type alias for the Thrift request/response body.
///
/// Currently uses `bytes::Bytes` for efficient memory management.
/// TODO: Support discontinuous memory in the future.
pub type ThriftBody = Bytes;
/// Type alias for a Thrift request using TTHeader protocol.
pub type ThriftRequest<T> = ;
/// Type alias for a Thrift response using TTHeader protocol.
pub type ThriftResponse<T> = ;
;
/// A trait for Thrift request handlers.
///
/// This trait defines the interface for processing Thrift requests and generating responses.
/// It is designed to work with asynchronous services and supports context-aware handling.
///
/// # Type Parameters
///
/// - `CX`: The context type for additional request processing information.
///
/// # Associated Types
///
/// - `Error`: The error type that may occur during request handling.
///
/// # Examples
///
/// ```ignore
/// use your_crate::{ThriftHandler, ThriftRequest, ThriftResponse, ThriftBody};
///
/// struct MyThriftHandler;
///
/// impl ThriftHandler<()> for MyThriftHandler {
/// type Error = std::io::Error;
///
/// async fn handle(&self, request: ThriftRequest<ThriftBody>, ctx: ())
/// -> Result<ThriftResponse<ThriftBody>, Self::Error> {
/// // Process the Thrift request and generate a response
/// let response = ThriftResponse::new(/* ... */);
/// Ok(response)
/// }
/// }
/// ```
///
/// The `ThriftHandler` trait is automatically implemented for types that implement the `Service`
/// trait with request type `(ThriftRequest<ThriftBody>, CX)` and response type
/// `ThriftResponse<ThriftBody>`.