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
use crateIpcError;
use ;
/// The `Serve` trait defines the interface for handling requests and generating responses in an IPC context.
/// Types implementing this trait can be used to process incoming requests and produce appropriate responses.
///
/// # Associated Types
///
/// * `Req` - The type of the request messages. It must implement `Serialize` and `Deserialize`.
/// * `Resp` - The type of the response messages. It must implement `Serialize` and `Deserialize`.
///
/// # Required Methods
///
/// * `serve` - This method is responsible for processing a single request and generating a response.
/// * `method` - This method extracts a method name from the request, if applicable. It returns an `Option` containing a static string slice representing the method name.
///
/// # Example
///
/// ```rust,ignore
/// use ckb_script_ipc_common::ipc::Serve;
/// use serde::{Serialize, Deserialize};
///
/// #[derive(Serialize, Deserialize)]
/// struct MyRequest {
/// // request fields
/// }
///
/// #[derive(Serialize, Deserialize)]
/// struct MyResponse {
/// // response fields
/// }
///
/// struct MyService;
///
/// impl Serve for MyService {
/// type Req = MyRequest;
/// type Resp = MyResponse;
///
/// fn serve(&mut self, req: Self::Req) -> Result<Self::Resp, IpcError> {
/// // process the request and generate a response
/// Ok(MyResponse { /* fields */ })
/// }
///
/// fn method(&self, _request: &Self::Req) -> Option<&'static str> {
/// Some("my_method")
/// }
/// }
/// ```