pub trait NetworkConnector {
type Stream: Into<Box<dyn NetworkStream + Send>>;
// Required method
fn connect(
&self,
host: &str,
port: u16,
scheme: &str,
) -> Result<Self::Stream, Error>;
}
Expand description
A connector creates a NetworkStream.
Required Associated Types§
Required Methods§
Implementors§
source§impl NetworkConnector for HttpConnector
impl NetworkConnector for HttpConnector
type Stream = HttpStream
source§impl<C, S> NetworkConnector for Pool<C>
impl<C, S> NetworkConnector for Pool<C>
type Stream = PooledStream<S>
source§impl<F> NetworkConnector for F
impl<F> NetworkConnector for F
A closure as a connector used to generate TcpStream
s per request
§Example
Basic example:
Client::with_connector(|addr: &str, port: u16, scheme: &str| {
TcpStream::connect(&(addr, port))
});
Example using TcpBuilder
from the net2 crate if you want to configure your source socket:
Client::with_connector(|addr: &str, port: u16, scheme: &str| {
let b = try!(TcpBuilder::new_v4());
try!(b.bind("127.0.0.1:0"));
b.connect(&(addr, port))
});