Skip to main content

rs_zero/rpc/
config.rs

1use std::{net::SocketAddr, time::Duration};
2
3/// RPC client configuration.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct RpcClientConfig {
6    /// Endpoint URI, for example `http://127.0.0.1:50051`.
7    pub endpoint: String,
8    /// Connection establishment timeout.
9    pub connect_timeout: Duration,
10    /// Per-request timeout.
11    pub request_timeout: Duration,
12}
13
14impl RpcClientConfig {
15    /// Creates a client config with practical defaults.
16    pub fn new(endpoint: impl Into<String>) -> Self {
17        Self {
18            endpoint: endpoint.into(),
19            connect_timeout: Duration::from_secs(3),
20            request_timeout: Duration::from_secs(5),
21        }
22    }
23}
24
25/// RPC server configuration.
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct RpcServerConfig {
28    /// Logical service name.
29    pub name: String,
30    /// Server listen address.
31    pub addr: SocketAddr,
32}
33
34impl RpcServerConfig {
35    /// Creates server config.
36    pub fn new(name: impl Into<String>, addr: SocketAddr) -> Self {
37        Self {
38            name: name.into(),
39            addr,
40        }
41    }
42}