use crate::sealed::Sealed;
use tokio::io::{AsyncRead, AsyncWrite};
use tower_async_service::Service;
pub trait MakeConnection<Target>: Sealed<(Target,)> {
type Connection: AsyncRead + AsyncWrite;
type Error;
fn make_connection(
&self,
target: Target,
) -> impl std::future::Future<Output = Result<Self::Connection, Self::Error>>;
}
impl<S, Target> Sealed<(Target,)> for S where S: Service<Target> {}
impl<C, Target> MakeConnection<Target> for C
where
C: Service<Target>,
C::Response: AsyncRead + AsyncWrite,
{
type Connection = C::Response;
type Error = C::Error;
async fn make_connection(&self, target: Target) -> Result<Self::Connection, Self::Error> {
Service::call(self, target).await
}
}