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
use client::Client;
use std::sync::Arc;
use ClientConf;
use Result as grpc_Result;
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) -> grpc_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> {
Client::new_plain(host, port, conf).map(|c| Self::with_client(Arc::new(c)))
}
fn new_tls<T: ::tls_api::TlsConnector>(
host: &str,
port: u16,
conf: ClientConf,
) -> grpc_Result<Self> {
Client::new_tls::<T>(host, port, conf).map(|c| Self::with_client(Arc::new(c)))
}
#[cfg(unix)]
fn new_plain_unix(addr: &str, conf: ClientConf) -> grpc_Result<Self> {
Client::new_plain_unix(addr, conf).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"))
}
}