Updated away from deprecated code in library.

This commit is contained in:
Aaron Weiss 2014-12-23 12:53:30 -05:00
parent b44ff8b196
commit 4fdf801fb3
8 changed files with 35 additions and 27 deletions

View file

@ -16,6 +16,10 @@ ctcp = ["time"]
encode = ["encoding"] encode = ["encoding"]
ssl = ["openssl"] ssl = ["openssl"]
[dependencies.rustc-serialize]
rustc-serialize = "~0.1.4"
[dependencies.time] [dependencies.time]
time = "~0.1.3" time = "~0.1.3"

View file

@ -932,7 +932,7 @@ impl<'a> Command<'a> {
} }
} else if let "CAP" = m.command[] { } else if let "CAP" = m.command[] {
if m.args.len() != 1 { return Err(invalid_input()) } 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 { match m.suffix {
Some(ref suffix) => Command::CAP(cmd, Some(suffix[])), Some(ref suffix) => Command::CAP(cmd, Some(suffix[])),
None => Command::CAP(cmd, None), None => Command::CAP(cmd, None),

View file

@ -1,12 +1,13 @@
//! JSON configuration files using libserialize. //! JSON configuration files using libserialize.
#![stable] #![stable]
use std::borrow::ToOwned;
use std::collections::HashMap; use std::collections::HashMap;
use std::io::fs::File; use std::io::fs::File;
use std::io::{InvalidInput, IoError, IoResult}; use std::io::{InvalidInput, IoError, IoResult};
use serialize::json::decode; use rustc_serialize::json::decode;
/// Configuration data. /// Configuration data.
#[deriving(Clone, Decodable, Default, PartialEq, Show)] #[deriving(Clone, RustcDecodable, Default, PartialEq, Show)]
#[unstable] #[unstable]
pub struct Config { pub struct Config {
/// A list of the owners of the bot by nickname. /// 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. /// This will also panic if used and there are no options.
#[experimental] #[experimental]
pub fn get_option(&self, option: &str) -> &str { 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()
} }
} }

View file

@ -1,5 +1,6 @@
//! Messages to and from the server. //! Messages to and from the server.
#![experimental] #![experimental]
use std::borrow::ToOwned;
use std::str::FromStr; use std::str::FromStr;
/// IRC Message data. /// IRC Message data.
@ -23,10 +24,10 @@ impl Message {
pub fn new(prefix: Option<&str>, command: &str, args: Option<Vec<&str>>, suffix: Option<&str>) pub fn new(prefix: Option<&str>, command: &str, args: Option<Vec<&str>>, suffix: Option<&str>)
-> Message { -> Message {
Message { Message {
prefix: prefix.map(|s| s.into_string()), prefix: prefix.map(|s| s.to_owned()),
command: command.into_string(), command: command.to_owned(),
args: args.map_or(Vec::new(), |v| v.iter().map(|s| s.into_string()).collect()), args: args.map_or(Vec::new(), |v| v.iter().map(|s| s.to_string()).collect()),
suffix: suffix.map(|s| s.into_string()), suffix: suffix.map(|s| s.to_owned()),
} }
} }
@ -125,13 +126,13 @@ mod test {
args: vec![format!("test")], args: vec![format!("test")],
suffix: Some(format!("Testing!")), 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 { let message = Message {
prefix: Some(format!("test!test@test")), prefix: Some(format!("test!test@test")),
command: format!("PRIVMSG"), command: format!("PRIVMSG"),
args: vec![format!("test")], args: vec![format!("test")],
suffix: Some(format!("Still testing!")), 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));
} }
} }

View file

@ -296,7 +296,7 @@ impl Response {
/// Gets a response from a message. /// Gets a response from a message.
#[stable] #[stable]
pub fn from_message(m: &Message) -> Option<Response> { pub fn from_message(m: &Message) -> Option<Response> {
from_str(m.command[]) m.command.parse()
} }
/// Determines whether or not this response is an error response. /// Determines whether or not this response is an error response.
@ -308,7 +308,7 @@ impl Response {
impl FromStr for Response { impl FromStr for Response {
fn from_str(s: &str) -> Option<Response> { fn from_str(s: &str) -> Option<Response> {
if let Some(respcode) = from_str(s) { if let Some(respcode) = s.parse() {
FromPrimitive::from_uint(respcode) FromPrimitive::from_uint(respcode)
} else { } else {
None None
@ -323,10 +323,10 @@ mod test {
#[test] #[test]
fn from_message() { fn from_message() {
assert_eq!(Response::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); ).unwrap(), Response::RPL_NAMREPLY);
assert_eq!(Response::from_message( assert_eq!(Response::from_message(
&from_str(":irc.test.net 433 <nick> :Nickname is already in use\r\n").unwrap() &":irc.test.net 433 <nick> :Nickname is already in use\r\n".parse().unwrap()
).unwrap(), Response::ERR_NICKNAMEINUSE); ).unwrap(), Response::ERR_NICKNAMEINUSE);
} }

View file

@ -1,5 +1,6 @@
//! Data for tracking user information. //! Data for tracking user information.
#![unstable] #![unstable]
use std::borrow::ToOwned;
use std::str::FromStr; use std::str::FromStr;
/// IRC User data. /// IRC User data.
@ -20,7 +21,7 @@ impl User {
pub fn new(name: &str) -> User { pub fn new(name: &str) -> User {
let ranks: Vec<_> = AccessLevelIterator::new(name).collect(); let ranks: Vec<_> = AccessLevelIterator::new(name).collect();
User { User {
name: name[ranks.len()..].into_string(), name: name[ranks.len()..].to_owned(),
access_levels: { access_levels: {
let mut ranks = ranks.clone(); let mut ranks = ranks.clone();
ranks.push(AccessLevel::Member); ranks.push(AccessLevel::Member);
@ -188,7 +189,7 @@ impl<'a> AccessLevelIterator<'a> {
impl<'a> Iterator<AccessLevel> for AccessLevelIterator<'a> { impl<'a> Iterator<AccessLevel> for AccessLevelIterator<'a> {
fn next(&mut self) -> Option<AccessLevel> { fn next(&mut self) -> Option<AccessLevel> {
let ret = from_str(self.value); let ret = self.value.parse();
if self.value.len() > 0 { if self.value.len() > 0 {
self.value = self.value[1..]; self.value = self.value[1..];
} }
@ -202,14 +203,14 @@ mod test {
use super::AccessLevel::{Admin, HalfOp, Member, Oper, Owner, Voice}; use super::AccessLevel::{Admin, HalfOp, Member, Oper, Owner, Voice};
#[test] #[test]
fn access_level_from_str() { fn parse_access_level() {
assert!(from_str::<AccessLevel>("member").is_none()); assert!("member".parse::<AccessLevel>().is_none());
assert_eq!(from_str::<AccessLevel>("~owner").unwrap(), Owner); assert_eq!("~owner".parse::<AccessLevel>().unwrap(), Owner);
assert_eq!(from_str::<AccessLevel>("&admin").unwrap(), Admin); assert_eq!("&admin".parse::<AccessLevel>().unwrap(), Admin);
assert_eq!(from_str::<AccessLevel>("@oper").unwrap(), Oper); assert_eq!("@oper".parse::<AccessLevel>().unwrap(), Oper);
assert_eq!(from_str::<AccessLevel>("%halfop").unwrap(), HalfOp); assert_eq!("%halfop".parse::<AccessLevel>().unwrap(), HalfOp);
assert_eq!(from_str::<AccessLevel>("+voice").unwrap(), Voice); assert_eq!("+voice".parse::<AccessLevel>().unwrap(), Voice);
assert!(from_str::<AccessLevel>("").is_none()); assert!("".parse::<AccessLevel>().is_none());
} }
#[test] #[test]

View file

@ -7,7 +7,7 @@
#![feature(slicing_syntax)] #![feature(slicing_syntax)]
#[cfg(feature = "ctcp")] extern crate time; #[cfg(feature = "ctcp")] extern crate time;
#[cfg(feature = "encode")] extern crate encoding; #[cfg(feature = "encode")] extern crate encoding;
extern crate serialize; extern crate "rustc-serialize" as rustc_serialize;
#[cfg(feature = "ssl")] extern crate openssl; #[cfg(feature = "ssl")] extern crate openssl;
pub mod conn; pub mod conn;

View file

@ -1,5 +1,6 @@
//! Interface for working with IRC Servers //! Interface for working with IRC Servers
#![experimental] #![experimental]
use std::borrow::ToOwned;
use std::collections::HashMap; use std::collections::HashMap;
use std::io::{BufferedReader, BufferedWriter, IoError, IoErrorKind, IoResult}; use std::io::{BufferedReader, BufferedWriter, IoError, IoErrorKind, IoResult};
use std::sync::{Mutex, RWLock}; use std::sync::{Mutex, RWLock};
@ -88,7 +89,7 @@ impl<'a, T: IrcReader, U: IrcWriter> Server<'a, T, U> for IrcServer<T, U> {
} }
fn list_users(&self, chan: &str) -> Option<Vec<User>> { fn list_users(&self, chan: &str) -> Option<Vec<User>> {
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<IoResult<Message>> for ServerIterator<'a, T, U> { impl<'a, T: IrcReader, U: IrcWriter> Iterator<IoResult<Message>> for ServerIterator<'a, T, U> {
fn next(&mut self) -> Option<IoResult<Message>> { fn next(&mut self) -> Option<IoResult<Message>> {
let res = self.get_next_line().and_then(|msg| let res = self.get_next_line().and_then(|msg|
match from_str(msg[]) { match msg.parse() {
Some(msg) => { Some(msg) => {
self.server.handle_message(&msg); self.server.handle_message(&msg);
Ok(msg) Ok(msg)