diff --git a/Cargo.toml b/Cargo.toml index cd287c8..5382107 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,10 @@ ctcp = ["time"] encode = ["encoding"] ssl = ["openssl"] +[dependencies.rustc-serialize] + +rustc-serialize = "~0.1.4" + [dependencies.time] time = "~0.1.3" diff --git a/src/data/command.rs b/src/data/command.rs index 097c749..a88f3b3 100644 --- a/src/data/command.rs +++ b/src/data/command.rs @@ -932,7 +932,7 @@ impl<'a> Command<'a> { } } else if let "CAP" = m.command[] { if m.args.len() != 1 { return Err(invalid_input()) } - if let Some(cmd) = from_str(m.args[0][]) { + if let Some(cmd) = m.args[0].parse() { match m.suffix { Some(ref suffix) => Command::CAP(cmd, Some(suffix[])), None => Command::CAP(cmd, None), diff --git a/src/data/config.rs b/src/data/config.rs index e494f74..c2c6496 100644 --- a/src/data/config.rs +++ b/src/data/config.rs @@ -1,12 +1,13 @@ //! JSON configuration files using libserialize. #![stable] +use std::borrow::ToOwned; use std::collections::HashMap; use std::io::fs::File; use std::io::{InvalidInput, IoError, IoResult}; -use serialize::json::decode; +use rustc_serialize::json::decode; /// Configuration data. -#[deriving(Clone, Decodable, Default, PartialEq, Show)] +#[deriving(Clone, RustcDecodable, Default, PartialEq, Show)] #[unstable] pub struct Config { /// A list of the owners of the bot by nickname. @@ -160,7 +161,7 @@ impl Config { /// This will also panic if used and there are no options. #[experimental] pub fn get_option(&self, option: &str) -> &str { - self.options.as_ref().map(|o| o[option.into_string()][]).unwrap() + self.options.as_ref().map(|o| o[option.to_owned()][]).unwrap() } } diff --git a/src/data/message.rs b/src/data/message.rs index 97a9bde..f62191e 100644 --- a/src/data/message.rs +++ b/src/data/message.rs @@ -1,5 +1,6 @@ //! Messages to and from the server. #![experimental] +use std::borrow::ToOwned; use std::str::FromStr; /// IRC Message data. @@ -23,10 +24,10 @@ impl Message { pub fn new(prefix: Option<&str>, command: &str, args: Option>, suffix: Option<&str>) -> Message { Message { - prefix: prefix.map(|s| s.into_string()), - command: command.into_string(), - args: args.map_or(Vec::new(), |v| v.iter().map(|s| s.into_string()).collect()), - suffix: suffix.map(|s| s.into_string()), + prefix: prefix.map(|s| s.to_owned()), + command: command.to_owned(), + args: args.map_or(Vec::new(), |v| v.iter().map(|s| s.to_string()).collect()), + suffix: suffix.map(|s| s.to_owned()), } } @@ -125,13 +126,13 @@ mod test { args: vec![format!("test")], suffix: Some(format!("Testing!")), }; - assert_eq!(from_str("PRIVMSG test :Testing!\r\n"), Some(message)); + assert_eq!("PRIVMSG test :Testing!\r\n".parse(), Some(message)); let message = Message { prefix: Some(format!("test!test@test")), command: format!("PRIVMSG"), args: vec![format!("test")], suffix: Some(format!("Still testing!")), }; - assert_eq!(from_str(":test!test@test PRIVMSG test :Still testing!\r\n"), Some(message)); + assert_eq!(":test!test@test PRIVMSG test :Still testing!\r\n".parse(), Some(message)); } } diff --git a/src/data/response.rs b/src/data/response.rs index ca83319..f6f06f7 100644 --- a/src/data/response.rs +++ b/src/data/response.rs @@ -296,7 +296,7 @@ impl Response { /// Gets a response from a message. #[stable] pub fn from_message(m: &Message) -> Option { - from_str(m.command[]) + m.command.parse() } /// Determines whether or not this response is an error response. @@ -308,7 +308,7 @@ impl Response { impl FromStr for Response { fn from_str(s: &str) -> Option { - if let Some(respcode) = from_str(s) { + if let Some(respcode) = s.parse() { FromPrimitive::from_uint(respcode) } else { None @@ -323,10 +323,10 @@ mod test { #[test] fn from_message() { assert_eq!(Response::from_message( - &from_str(":irc.test.net 353 test = #test :test\r\n").unwrap() + &":irc.test.net 353 test = #test :test\r\n".parse().unwrap() ).unwrap(), Response::RPL_NAMREPLY); assert_eq!(Response::from_message( - &from_str(":irc.test.net 433 :Nickname is already in use\r\n").unwrap() + &":irc.test.net 433 :Nickname is already in use\r\n".parse().unwrap() ).unwrap(), Response::ERR_NICKNAMEINUSE); } diff --git a/src/data/user.rs b/src/data/user.rs index c862f25..252bc66 100644 --- a/src/data/user.rs +++ b/src/data/user.rs @@ -1,5 +1,6 @@ //! Data for tracking user information. #![unstable] +use std::borrow::ToOwned; use std::str::FromStr; /// IRC User data. @@ -20,7 +21,7 @@ impl User { pub fn new(name: &str) -> User { let ranks: Vec<_> = AccessLevelIterator::new(name).collect(); User { - name: name[ranks.len()..].into_string(), + name: name[ranks.len()..].to_owned(), access_levels: { let mut ranks = ranks.clone(); ranks.push(AccessLevel::Member); @@ -188,7 +189,7 @@ impl<'a> AccessLevelIterator<'a> { impl<'a> Iterator for AccessLevelIterator<'a> { fn next(&mut self) -> Option { - let ret = from_str(self.value); + let ret = self.value.parse(); if self.value.len() > 0 { self.value = self.value[1..]; } @@ -202,14 +203,14 @@ mod test { use super::AccessLevel::{Admin, HalfOp, Member, Oper, Owner, Voice}; #[test] - fn access_level_from_str() { - assert!(from_str::("member").is_none()); - assert_eq!(from_str::("~owner").unwrap(), Owner); - assert_eq!(from_str::("&admin").unwrap(), Admin); - assert_eq!(from_str::("@oper").unwrap(), Oper); - assert_eq!(from_str::("%halfop").unwrap(), HalfOp); - assert_eq!(from_str::("+voice").unwrap(), Voice); - assert!(from_str::("").is_none()); + fn parse_access_level() { + assert!("member".parse::().is_none()); + assert_eq!("~owner".parse::().unwrap(), Owner); + assert_eq!("&admin".parse::().unwrap(), Admin); + assert_eq!("@oper".parse::().unwrap(), Oper); + assert_eq!("%halfop".parse::().unwrap(), HalfOp); + assert_eq!("+voice".parse::().unwrap(), Voice); + assert!("".parse::().is_none()); } #[test] diff --git a/src/lib.rs b/src/lib.rs index aa9fe8f..0efc393 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ #![feature(slicing_syntax)] #[cfg(feature = "ctcp")] extern crate time; #[cfg(feature = "encode")] extern crate encoding; -extern crate serialize; +extern crate "rustc-serialize" as rustc_serialize; #[cfg(feature = "ssl")] extern crate openssl; pub mod conn; diff --git a/src/server/mod.rs b/src/server/mod.rs index 1bd74dd..4645130 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,5 +1,6 @@ //! Interface for working with IRC Servers #![experimental] +use std::borrow::ToOwned; use std::collections::HashMap; use std::io::{BufferedReader, BufferedWriter, IoError, IoErrorKind, IoResult}; use std::sync::{Mutex, RWLock}; @@ -88,7 +89,7 @@ impl<'a, T: IrcReader, U: IrcWriter> Server<'a, T, U> for IrcServer { } fn list_users(&self, chan: &str) -> Option> { - self.chanlists.lock().get(&chan.into_string()).cloned() + self.chanlists.lock().get(&chan.to_owned()).cloned() } } @@ -261,7 +262,7 @@ impl<'a, T: IrcReader, U: IrcWriter> ServerIterator<'a, T, U> { impl<'a, T: IrcReader, U: IrcWriter> Iterator> for ServerIterator<'a, T, U> { fn next(&mut self) -> Option> { let res = self.get_next_line().and_then(|msg| - match from_str(msg[]) { + match msg.parse() { Some(msg) => { self.server.handle_message(&msg); Ok(msg)