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"))
}
}