Skip to content

Instantly share code, notes, and snippets.

@LucioFranco
Created December 14, 2018 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucioFranco/4372bcb6ebb3f180324ac1def7129f86 to your computer and use it in GitHub Desktop.
Save LucioFranco/4372bcb6ebb3f180324ac1def7129f86 to your computer and use it in GitHub Desktop.
use tower_service::Service;
use futures::Future;
use tokio_io::{AsyncRead, AsyncWrite};
use std::net::ToSocketAddrs;
pub trait ConnectService<A: ToSocketAddrs>{
type Response: AsyncRead + AsyncWrite;
type Error;
type Service: Service<A>;
type Future: Future<Item = Self::Response, Error = Self::Error>;
fn connect(&self, target: A) -> Self::Future;
}
impl<A, S, C, Request> ConnectService<A> for C
where A: ToSocketAddrs,
C: Service<A>,
C::Response: AsyncRead + AsyncWrite,
S: Service<Request>,
{
type Response = C::Response;
type Error = S::Error;
type Service = S;
type Error = C::Error;
type Future = C::Future;
fn connect(&mut self, target: A) -> Self::Future {
ConnectService::connect(self, target)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment