mill_rpc_core/context.rs
1use std::net::SocketAddr;
2
3/// Context available to RPC handlers during request processing.
4///
5/// Provides metadata about the current request and the connection it arrived on.
6#[derive(Debug, Clone)]
7pub struct RpcContext {
8 /// Unique ID for this request.
9 pub request_id: u64,
10 /// Peer address of the client.
11 pub peer_addr: Option<SocketAddr>,
12 /// Service ID being called.
13 pub service_id: u16,
14 /// Method ID being called.
15 pub method_id: u16,
16}
17
18impl RpcContext {
19 pub fn new(request_id: u64, service_id: u16, method_id: u16) -> Self {
20 Self {
21 request_id,
22 peer_addr: None,
23 service_id,
24 method_id,
25 }
26 }
27
28 pub fn with_peer_addr(mut self, addr: SocketAddr) -> Self {
29 self.peer_addr = Some(addr);
30 self
31 }
32}