tk_pool/
connect.rs

1use std::net::SocketAddr;
2
3use futures::{Future, IntoFuture};
4
5
6/// This is a trait that is used for establishing a connection
7///
8/// Usually just passing a closure is good enough
9pub trait Connect {
10    /// A future retuned by `connect` method
11    type Future: Future;
12    /// Establish a connection to the specified address
13    fn connect(&mut self, address: SocketAddr) -> Self::Future;
14}
15
16impl<T, F> Connect for T
17    where T: FnMut(SocketAddr) -> F,
18          F: IntoFuture,
19{
20    type Future = <T::Output as IntoFuture>::Future;
21    fn connect(&mut self, address: SocketAddr) -> Self::Future {
22        (self)(address).into_future()
23    }
24}