aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Hoeppner2015-04-18 14:55:40 +0200
committerTill Hoeppner2015-04-18 14:55:40 +0200
commita8c80253d6361728db95e6a5640a91a341ad4ea5 (patch)
tree4755946bbf479a294e85457177884988e05c29c0
parentbb94e44ed6ec5b55823270192c00904cbfb24b6b (diff)
downloadirsc-a8c80253d6361728db95e6a5640a91a341ad4ea5.tar.gz
irsc-a8c80253d6361728db95e6a5640a91a341ad4ea5.tar.xz
irsc-a8c80253d6361728db95e6a5640a91a341ad4ea5.zip
Fix Option/Result confusions + fixes for stability
-rw-r--r--src/lib.rs7
-rw-r--r--src/message.rs20
-rw-r--r--src/server.rs18
3 files changed, 21 insertions, 24 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7cf7c9d..577770d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,12 +1,9 @@
-#![feature(plugin, slicing_syntax, unboxed_closures)]
-#![allow(unstable)]
-
+#![feature(plugin, collections)]
#![plugin(regex_macros)]
-extern crate regex;
+extern crate regex;
#[macro_use]
extern crate log;
-
extern crate eventual;
pub mod server;
diff --git a/src/message.rs b/src/message.rs
index 4adc83a..dfe7f29 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -2,7 +2,7 @@
use std::str::FromStr;
use std::string::{ ToString };
-use std::borrow::{ Cow, ToOwned };
+use std::borrow::{ Cow, Borrow, ToOwned };
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum MsgType {
@@ -41,9 +41,9 @@ impl<'a> FromStr for Message<'a> {
let len = i.len();
let mut s = i;
- let msg_type = if s.char_at(0) == '\u{1}' { MsgType::Ctcp } else { MsgType::Irc };
+ let msg_type = if s.chars().next() == Some('\u{1}') { MsgType::Ctcp } else { MsgType::Irc };
- let prefix = if len >= 1 && s.char_at(0) == ':' {
+ let prefix = if len >= 1 && s.chars().next() == Some(':') {
s.find(' ').map(|i| {
let p = s.slice_chars(1, i).to_owned();
s = &s[i + 1..];
@@ -55,14 +55,14 @@ impl<'a> FromStr for Message<'a> {
let p = s.slice_chars(0, i).to_owned();
s = &s[i..];
p
- }).map(|c| c.parse()).map(|c| Some(Cow::Owned(c)));
+ }).map(|c| c.parse()).map(|c| Some(Cow::Owned(c.unwrap())));
// TODO: Parse last non-suffix argument as suffix if no suffix
// with colon is available.
let mut content = Vec::with_capacity(15);
let mut suffix = None;
while s.len() > 0 {
- if s.char_at(0) == ':' {
+ if s.chars().next() == Some(':') {
suffix = Some(s[1..].to_owned());
break
}
@@ -72,17 +72,17 @@ impl<'a> FromStr for Message<'a> {
s = &s[i..];
}
});
- if s.char_at(0) == ' ' { s = &s[1..] };
+ if s.chars().next() == Some(' ') { s = &s[1..] };
}
- command.and_then(move |Ok(c)|
+ command.map(move |c|
Ok(Message::new(prefix.map(|p| Cow::Owned(p)),
- c,
+ c.unwrap(),
content,
suffix.map(|s| Cow::Owned(s)),
msg_type
))
- )
+ ).unwrap()
}
}
@@ -1110,7 +1110,7 @@ impl FromStr for Command {
impl<'a> Command<'a> {
pub fn from_message(msg: &'a Message) -> Option<Command<'a>> {
- match &msg.command {
+ match &msg.command.as_ref()[..] {
"NOTICE" => msg.content.get(0).and_then(|c| msg.content.get(1).map(|t|
Command::Notice { to: Cow::Borrowed(&t), content: Cow::Borrowed(&c) })),
"PING" => msg.content.get(0).and_then(|s1| msg.content.get(1).map(|s2|
diff --git a/src/server.rs b/src/server.rs
index 9c4bb65..dfe5051 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -2,7 +2,7 @@ use std::io::{
self,
Write,
Read,
- BufRead,
+// BufRead,
BufReader,
};
@@ -69,7 +69,7 @@ impl Server {
pub fn connect(&mut self, host: String, port: u16) -> ::Result<()> {
let s = &mut self.stream;
match *s { Some(_) => return Err(::IrscError::AlreadyConnected), _ => () };
- *s = match TcpStream::connect((host.as_slice(), port)) {
+ *s = match TcpStream::connect((host.as_ref(), port)) {
Ok(tcp) => Some(StreamKind::Plain(tcp)),
Err(e) => return Err(::IrscError::Io(e))
};
@@ -81,7 +81,7 @@ impl Server {
pub fn connect_ssl(&mut self, host: String, port: u16) -> ::Result<()> {
let mut s = self.stream.lock();
match *s { Some(_) => return Err(::IrscError::AlreadyConnected), _ => () };
- let tcp_stream = match TcpStream::connect((host.as_slice(), port)) {
+ let tcp_stream = match TcpStream::connect((host.as_ref(), port)) {
Ok(tcp) => Some(tcp),
Err(e) => return Err(::IrscError::Io(e))
};
@@ -123,27 +123,27 @@ impl Server {
}
pub fn join(&mut self, channel: &str) -> ::Result<usize> {
- self.sendraw(format!("JOIN {}", channel).as_slice(), true)
+ self.sendraw(format!("JOIN {}", channel).as_ref(), true)
}
pub fn part(&mut self, channel: &str) -> ::Result<usize> {
- self.sendraw(format!("PART {}", channel).as_slice(), true)
+ self.sendraw(format!("PART {}", channel).as_ref(), true)
}
pub fn nick(&mut self, nick: &str) -> ::Result<usize> {
- self.sendraw(format!("NICK {}", nick).as_slice(), true)
+ self.sendraw(format!("NICK {}", nick).as_ref(), true)
}
pub fn user(&mut self, username: &str, hostname: &str, servername: &str, realname: &str) -> ::Result<usize> {
- self.sendraw(format!("USER {} {} {} :{}", username, hostname, servername, realname).as_slice(), true)
+ self.sendraw(format!("USER {} {} {} :{}", username, hostname, servername, realname).as_ref(), true)
}
pub fn password(&mut self, password: &str) -> ::Result<usize> {
- self.sendraw(format!("PASS {}", password).as_slice(), true)
+ self.sendraw(format!("PASS {}", password).as_ref(), true)
}
pub fn msg(&mut self, target: &str, message: &str) -> ::Result<usize> {
- self.sendraw(format!("PRIVMSG {} :{}", target, message).as_slice(), true)
+ self.sendraw(format!("PRIVMSG {} :{}", target, message).as_ref(), true)
}
pub fn listen(&mut self, events: &[fn(&mut Server, &Message)]) -> ::Result<()> {