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:
		
							
								
								
									
										15
									
								
								src/net.rs
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/net.rs
									
									
									
									
									
								
							| @@ -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> { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user