feat(client): remove generic parameter for Connector

Closes #379

BREAKING CHANGE: For people using the default HttpConnector and Client,
    everything should continue to just work. If the Client has been
    used with a generic parameter, it should be removed.

    However, there were some breaking changes to the internals of
    NetworkConnectors. Specifically, they no longer return a
    NetworkStream, but instead a Into<Box<NetworkStream + Send>>. All
    implementations of NetworkStream should continue to just work,
    however.

    Possible breakages could come from the stricter usage of Send
    throughout the Client API.
This commit is contained in:
Sean McArthur
2015-04-03 17:06:44 -07:00
parent 4fecd64c0f
commit 139a51f1c3
4 changed files with 64 additions and 37 deletions

View File

@@ -83,11 +83,17 @@ impl<T: NetworkStream + Send + Clone> StreamClone for T {
/// A connector creates a NetworkStream.
pub trait NetworkConnector {
/// Type of Stream to create
type Stream: NetworkStream + Send;
type Stream: Into<Box<NetworkStream + Send>>;
/// Connect to a remote address.
fn connect(&mut self, host: &str, port: u16, scheme: &str) -> io::Result<Self::Stream>;
}
impl<T: NetworkStream + Send> From<T> for Box<NetworkStream + Send> {
fn from(s: T) -> Box<NetworkStream + Send> {
Box::new(s)
}
}
impl fmt::Debug for Box<NetworkStream + Send> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.pad("Box<NetworkStream>")
@@ -294,13 +300,12 @@ impl NetworkStream for HttpStream {
}
/// A connector that will produce HttpStreams.
#[allow(missing_copy_implementations)]
pub struct HttpConnector<'v>(pub Option<ContextVerifier<'v>>);
pub struct HttpConnector(pub Option<ContextVerifier>);
/// A method that can set verification methods on an SSL context
pub type ContextVerifier<'v> = Box<FnMut(&mut SslContext) -> ()+'v>;
pub type ContextVerifier = Box<FnMut(&mut SslContext) -> () + Send>;
impl<'v> NetworkConnector for HttpConnector<'v> {
impl NetworkConnector for HttpConnector {
type Stream = HttpStream;
fn connect(&mut self, host: &str, port: u16, scheme: &str) -> io::Result<HttpStream> {