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
use crate::client::Client;
use crate::client::ClientBuilder;
use crate::ClientConf;
use crate::Result as grpc_Result;
use std::sync::Arc;
pub trait ClientStub: Sized {
fn with_client(grpc_client: Arc<Client>) -> Self;
}
pub trait ClientStubExt: Sized {
fn new_plain(host: &str, port: u16, conf: ClientConf) -> crate::Result<Self>;
fn new_tls<C: ::tls_api::TlsConnector>(
host: &str,
port: u16,
conf: ClientConf,
) -> grpc_Result<Self>;
fn new_plain_unix(addr: &str, conf: ClientConf) -> grpc_Result<Self>;
}
impl<C: ClientStub> ClientStubExt for C {
fn new_plain(host: &str, port: u16, conf: ClientConf) -> grpc_Result<Self> {
ClientBuilder::new(host, port)
.conf(conf)
.build()
.map(|c| Self::with_client(Arc::new(c)))
}
fn new_tls<T: ::tls_api::TlsConnector>(
host: &str,
port: u16,
conf: ClientConf,
) -> grpc_Result<Self> {
ClientBuilder::new(host, port)
.tls::<T>()
.conf(conf)
.build()
.map(|c| Self::with_client(Arc::new(c)))
}
#[cfg(unix)]
fn new_plain_unix(addr: &str, conf: ClientConf) -> grpc_Result<Self> {
ClientBuilder::new_unix(addr)
.conf(conf)
.build()
.map(|c| Self::with_client(Arc::new(c)))
}
#[cfg(not(unix))]
fn new_plain_unix(addr: &str, conf: ClientConf) -> grpc_Result<Self> {
Err(::Error::Other("new_plain_unix unsupported"))
}
}