Merge pull request #1 from arges/master

Allow connect to take both &str and String
This commit is contained in:
Matt McCoy 2015-06-15 15:05:27 -04:00
commit 9fb61353af

View file

@ -10,7 +10,7 @@ enum IMAPStreamTypes {
pub struct IMAPStream { pub struct IMAPStream {
stream: IMAPStreamTypes, stream: IMAPStreamTypes,
pub host: &'static str, pub host: String,
pub port: u16, pub port: u16,
tag: u32, tag: u32,
tag_prefix: &'static str tag_prefix: &'static str
@ -28,12 +28,13 @@ pub struct IMAPMailbox {
impl IMAPStream { impl IMAPStream {
pub fn connect(host: &'static str, port: u16, ssl_context: Option<SslContext>) -> Result<IMAPStream> { pub fn connect<S: Into<String>>(host: S, port: u16, ssl_context: Option<SslContext>) -> Result<IMAPStream> {
let connect_string = format!("{}:{}", host, port); let host_string = host.into();
let connect_string = format!("{}:{}", host_string, port);
let tcp_stream = TcpStream::connect(&*connect_string).unwrap(); let tcp_stream = TcpStream::connect(&*connect_string).unwrap();
let mut socket = match ssl_context { let mut socket = match ssl_context {
Some(context) => IMAPStream { stream: IMAPStreamTypes::Ssl(SslStream::new(&context, tcp_stream).unwrap()), host: host, port: port, tag: 1, tag_prefix: "a"}, Some(context) => IMAPStream { stream: IMAPStreamTypes::Ssl(SslStream::new(&context, tcp_stream).unwrap()), host: host_string, port: port, tag: 1, tag_prefix: "a"},
None => IMAPStream { stream: IMAPStreamTypes::Basic(tcp_stream), host: host, port: port, tag: 1, tag_prefix: "a"}, None => IMAPStream { stream: IMAPStreamTypes::Basic(tcp_stream), host: host_string, port: port, tag: 1, tag_prefix: "a"},
}; };
match socket.read_greeting() { match socket.read_greeting() {