Last active
August 29, 2015 14:26
-
-
Save muja/6fe0237e2f776d8e8299 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct TcpBuilderConnector<F: Fn() -> io::Result<TcpBuilder>> { | |
pub create: F | |
} | |
impl Default for TcpBuilderConnector<fn() -> io::Result<TcpBuilder>> { | |
fn default() -> Self { | |
TcpBuilderConnector { | |
create: TcpBuilder::new_v4 | |
} | |
// Compiling hyper v0.6.5 | |
// src/net.rs:259:9: 261:10 error: mismatched types: | |
// expected `net::TcpBuilderConnector<fn() -> core::result::Result<net2::tcp::TcpBuilder, std::io::error::Error>>`, | |
// found `net::TcpBuilderConnector<fn() -> core::result::Result<net2::tcp::TcpBuilder, std::io::error::Error> {net2::tcp::TcpBuilder::new_v4}>` | |
// (expected fn pointer, | |
// found fn item) [E0308] | |
} | |
} | |
impl<F: Fn() -> io::Result<TcpBuilder>> NetworkConnector for TcpBuilderConnector<F> { | |
type Stream = HttpStream; | |
fn connect(&self, host: &str, port: u16, scheme: &str) -> ::Result<HttpStream> { | |
let remote_addr = &(host, port); | |
Ok(try!(match scheme { | |
"http" => { | |
debug!("http scheme"); | |
let builder = try!((self.create)()); | |
Ok(HttpStream(try!(builder.connect(remote_addr)))) | |
}, | |
_ => { | |
Err(io::Error::new(io::ErrorKind::InvalidInput, | |
"Invalid scheme for Http")) | |
} | |
})) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment