Updated away from deprecated code in library.
This commit is contained in:
parent
b44ff8b196
commit
4fdf801fb3
8 changed files with 35 additions and 27 deletions
|
@ -16,6 +16,10 @@ ctcp = ["time"]
|
|||
encode = ["encoding"]
|
||||
ssl = ["openssl"]
|
||||
|
||||
[dependencies.rustc-serialize]
|
||||
|
||||
rustc-serialize = "~0.1.4"
|
||||
|
||||
[dependencies.time]
|
||||
|
||||
time = "~0.1.3"
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Vec<&str>>, 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ impl Response {
|
|||
/// Gets a response from a message.
|
||||
#[stable]
|
||||
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.
|
||||
|
@ -308,7 +308,7 @@ impl Response {
|
|||
|
||||
impl FromStr for 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)
|
||||
} 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 <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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<AccessLevel> for AccessLevelIterator<'a> {
|
||||
fn next(&mut self) -> Option<AccessLevel> {
|
||||
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::<AccessLevel>("member").is_none());
|
||||
assert_eq!(from_str::<AccessLevel>("~owner").unwrap(), Owner);
|
||||
assert_eq!(from_str::<AccessLevel>("&admin").unwrap(), Admin);
|
||||
assert_eq!(from_str::<AccessLevel>("@oper").unwrap(), Oper);
|
||||
assert_eq!(from_str::<AccessLevel>("%halfop").unwrap(), HalfOp);
|
||||
assert_eq!(from_str::<AccessLevel>("+voice").unwrap(), Voice);
|
||||
assert!(from_str::<AccessLevel>("").is_none());
|
||||
fn parse_access_level() {
|
||||
assert!("member".parse::<AccessLevel>().is_none());
|
||||
assert_eq!("~owner".parse::<AccessLevel>().unwrap(), Owner);
|
||||
assert_eq!("&admin".parse::<AccessLevel>().unwrap(), Admin);
|
||||
assert_eq!("@oper".parse::<AccessLevel>().unwrap(), Oper);
|
||||
assert_eq!("%halfop".parse::<AccessLevel>().unwrap(), HalfOp);
|
||||
assert_eq!("+voice".parse::<AccessLevel>().unwrap(), Voice);
|
||||
assert!("".parse::<AccessLevel>().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<T, U> {
|
|||
}
|
||||
|
||||
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> {
|
||||
fn next(&mut self) -> Option<IoResult<Message>> {
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue