From ceb4ae699383ce2a1578a69a38b2efa384484b90 Mon Sep 17 00:00:00 2001 From: Chris J Arges Date: Sun, 14 Jun 2015 23:23:38 -0500 Subject: [PATCH] Allow connect to take both &str and String It would be useful to allow a String to be passed to connect instead of just a &'static str. This code makes 'host' a String type, but allows the function to take either type. --- src/client.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/client.rs b/src/client.rs index 09b0509..391f81d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -10,7 +10,7 @@ enum IMAPStreamTypes { pub struct IMAPStream { stream: IMAPStreamTypes, - pub host: &'static str, + pub host: String, pub port: u16, tag: u32, tag_prefix: &'static str @@ -28,12 +28,13 @@ pub struct IMAPMailbox { impl IMAPStream { - pub fn connect(host: &'static str, port: u16, ssl_context: Option) -> Result { - let connect_string = format!("{}:{}", host, port); + pub fn connect>(host: S, port: u16, ssl_context: Option) -> Result { + let host_string = host.into(); + let connect_string = format!("{}:{}", host_string, port); let tcp_stream = TcpStream::connect(&*connect_string).unwrap(); 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"}, - None => IMAPStream { stream: IMAPStreamTypes::Basic(tcp_stream), 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_string, port: port, tag: 1, tag_prefix: "a"}, }; match socket.read_greeting() {