use futures::Future;
use tokio::io::{AsyncRead, AsyncWrite};
use crate::{sealed::Sealed, UnaryService};
pub trait MakeConnection<Address>: Sealed<(Address,)> {
type Connection: AsyncRead + AsyncWrite + Unpin + Send;
type Error;
#[cfg(feature = "service_send")]
fn make_connection(
&self,
req: Address,
) -> impl Future<Output = Result<Self::Connection, Self::Error>> + Send;
#[cfg(not(feature = "service_send"))]
fn make_connection(
&self,
req: Address,
) -> impl Future<Output = Result<Self::Connection, Self::Error>>;
}
impl<S, Address> Sealed<(Address,)> for S where S: UnaryService<Address> {}
impl<S, Address> MakeConnection<Address> for S
where
S: UnaryService<Address>,
S::Response: AsyncRead + AsyncWrite + Unpin + Send,
{
type Connection = S::Response;
type Error = S::Error;
#[cfg(feature = "service_send")]
fn make_connection(
&self,
addr: Address,
) -> impl Future<Output = Result<Self::Connection, Self::Error>> + Send {
self.call(addr)
}
#[cfg(not(feature = "service_send"))]
fn make_connection(
&self,
addr: Address,
) -> impl Future<Output = Result<Self::Connection, Self::Error>> {
self.call(addr)
}
}