From 23fa48d41e3c0eebbb490d5f99ef31f61f6af0ca Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Fri, 3 Apr 2015 00:56:42 -0400 Subject: [PATCH] Updated for Rust master. --- examples/tweeter.rs | 6 ++---- src/client/conn.rs | 34 ++++++++++++++++++---------------- src/client/data/command.rs | 2 +- src/client/data/config.rs | 10 ++++------ src/client/server/mod.rs | 5 +++-- src/lib.rs | 2 +- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/examples/tweeter.rs b/examples/tweeter.rs index 4f6e707..1846822 100644 --- a/examples/tweeter.rs +++ b/examples/tweeter.rs @@ -1,10 +1,8 @@ -#![feature(std_misc, thread_sleep)] extern crate irc; use std::default::Default; use std::sync::Arc; -use std::thread::{sleep, spawn}; -use std::time::duration::Duration; +use std::thread::{sleep_ms, spawn}; use irc::client::prelude::*; fn main() { @@ -23,6 +21,6 @@ fn main() { }); loop { server.send_privmsg("#vana", "TWEET TWEET").unwrap(); - sleep(Duration::seconds(10)) + sleep_ms(10 * 1000); } } diff --git a/src/client/conn.rs b/src/client/conn.rs index 8b0730d..2af9144 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -1,10 +1,9 @@ //! Thread-safe connections on IrcStreams. #![stable] -#[cfg(feature = "ssl")] use std::borrow::ToOwned; -#[cfg(feature = "ssl")] use std::error::Error; +#[cfg(feature = "ssl")] use std::error::Error as StdError; use std::io::prelude::*; use std::io::{BufReader, BufWriter, Result}; -use std::io::Error as IoError; +use std::io::Error; use std::io::ErrorKind; use std::net::TcpStream; #[cfg(feature = "ssl")] use std::result::Result as StdResult; @@ -120,15 +119,15 @@ impl Connection { pub fn send(&self, to_msg: M, encoding: &str) -> Result<()> { let encoding = match encoding_from_whatwg_label(encoding) { Some(enc) => enc, - None => return Err(IoError::new(ErrorKind::InvalidInput, "Failed to find encoder.", - Some(format!("Invalid encoder: {}", encoding)))) + None => return Err(Error::new( + ErrorKind::InvalidInput, &format!("Failed to find encoder. ({})", encoding)[..] + )) }; let msg = to_msg.to_message(); let data = match encoding.encode(&msg.into_string(), EncoderTrap::Replace) { Ok(data) => data, - Err(data) => return Err(IoError::new( - ErrorKind::InvalidInput, "Failed to encode message.", - Some(format!("Failed to encode {} as {}.", data, encoding.name())) + Err(data) => return Err(Error::new(ErrorKind::InvalidInput, + &format!("Failed to encode {} as {}.", data, encoding.name())[..] )) }; let mut writer = self.writer.lock().unwrap(); @@ -151,16 +150,18 @@ impl Connection { pub fn recv(&self, encoding: &str) -> Result { let encoding = match encoding_from_whatwg_label(encoding) { Some(enc) => enc, - None => return Err(IoError::new(ErrorKind::InvalidInput, "Failed to find decoder.", - Some(format!("Invalid decoder: {}", encoding)))) + None => return Err(Error::new( + ErrorKind::InvalidInput, &format!("Failed to find decoder. ({})", encoding)[..] + )) }; let mut buf = Vec::new(); self.reader.lock().unwrap().read_until(b'\n', &mut buf).and_then(|_| match encoding.decode(&buf, DecoderTrap::Replace) { - _ if buf.is_empty() => Err(IoError::new(ErrorKind::Other, "EOF", None)), + _ if buf.is_empty() => Err(Error::new(ErrorKind::Other, "EOF")), Ok(data) => Ok(data), - Err(data) => Err(IoError::new(ErrorKind::InvalidInput, "Failed to decode message.", - Some(format!("Failed to decode {} as {}.", data, encoding.name())))) + Err(data) => return Err(Error::new(ErrorKind::InvalidInput, + &format!("Failed to decode {} as {}.", data, encoding.name())[..] + )) } ) } @@ -172,7 +173,7 @@ impl Connection { let mut ret = String::new(); try!(self.reader.lock().unwrap().read_line(&mut ret)); if ret.is_empty() { - Err(IoError::new(ErrorKind::Other, "EOF", None)) + Err(Error::new(ErrorKind::Other, "EOF")) } else { Ok(ret) } @@ -196,8 +197,9 @@ impl Connection { fn ssl_to_io(res: StdResult) -> Result { match res { Ok(x) => Ok(x), - Err(e) => Err(IoError::new(ErrorKind::Other, "An SSL error occurred.", - Some(e.description().to_owned()))), + Err(e) => Err(Error::new(ErrorKind::Other, + &format!("An SSL error occurred. ({})", e.description())[..] + )), } } diff --git a/src/client/data/command.rs b/src/client/data/command.rs index ed0a788..f7d8d9b 100644 --- a/src/client/data/command.rs +++ b/src/client/data/command.rs @@ -1154,5 +1154,5 @@ impl FromStr for CapSubCommand { /// Produces an invalid_input IoError. fn invalid_input() -> Error { - Error::new(ErrorKind::InvalidInput, "Failed to parse malformed message as command.", None) + Error::new(ErrorKind::InvalidInput, "Failed to parse malformed message as command.") } diff --git a/src/client/data/config.rs b/src/client/data/config.rs index 9a2742b..ce34fac 100644 --- a/src/client/data/config.rs +++ b/src/client/data/config.rs @@ -2,7 +2,6 @@ #![stable] use std::borrow::ToOwned; use std::collections::HashMap; -use std::error::Error as StdError; use std::fs::File; use std::io::prelude::*; use std::io::{Error, ErrorKind, Result}; @@ -70,9 +69,8 @@ impl Config { let mut file = try!(File::open(path)); let mut data = String::new(); try!(file.read_to_string(&mut data)); - decode(&data[..]).map_err(|e| - Error::new(ErrorKind::InvalidInput, "Failed to decode configuration file.", - Some(e.description().to_owned())) + decode(&data[..]).map_err(|_| + Error::new(ErrorKind::InvalidInput, "Failed to decode configuration file.") ) } @@ -219,7 +217,7 @@ mod test { user_info: None, options: Some(HashMap::new()), }; - assert_eq!(Config::load(Path::new("client_config.json")), Ok(cfg)); + assert_eq!(Config::load(Path::new("client_config.json")).unwrap(), cfg); } #[test] @@ -241,7 +239,7 @@ mod test { user_info: None, options: Some(HashMap::new()), }; - assert_eq!(Config::load_utf8("client_config.json"), Ok(cfg)); + assert_eq!(Config::load_utf8("client_config.json").unwrap(), cfg); } diff --git a/src/client/server/mod.rs b/src/client/server/mod.rs index 8fd2ca8..b29e107 100644 --- a/src/client/server/mod.rs +++ b/src/client/server/mod.rs @@ -304,8 +304,9 @@ impl<'a, T: IrcRead, U: IrcWrite> Iterator for ServerIterator<'a, T, U> { self.server.handle_message(&msg); Ok(msg) }, - Err(m) => Err(Error::new(ErrorKind::InvalidInput, "Failed to parse message.", - Some(format!("{} (Message: {})", m, msg)))) + Err(_) => Err(Error::new(ErrorKind::InvalidInput, + &format!("Failed to parse message. (Message: {})", msg)[..] + )) } ); match res { diff --git a/src/lib.rs b/src/lib.rs index a1ec5eb..7125eca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ #![unstable] #![warn(missing_docs)] -#![feature(collections, core, io, slice_patterns, str_char, tcp)] +#![feature(collections, core, slice_patterns, str_char, tcp)] #[cfg(feature = "ctcp")] extern crate time; #[cfg(feature = "encode")] extern crate encoding; extern crate rustc_serialize;