aboutsummaryrefslogtreecommitdiff
path: root/src/message.rs
diff options
context:
space:
mode:
authorTill Hoeppner2015-04-21 13:42:24 +0200
committerTill Hoeppner2015-04-21 13:42:24 +0200
commitc67d6c211918f8b787b862bb580c41224a8d50c7 (patch)
treed432b1a08106fdbd1edaa0ac5ce397ed642aa101 /src/message.rs
parent1ebf3c02d9c5bd967c1d45e6db343903bbdef777 (diff)
downloadirsc-c67d6c211918f8b787b862bb580c41224a8d50c7.tar.gz
irsc-c67d6c211918f8b787b862bb580c41224a8d50c7.tar.xz
irsc-c67d6c211918f8b787b862bb580c41224a8d50c7.zip
Parse and format PASS, NICK, USER, OPER, PING, PONG, JOIN, PART
Diffstat (limited to 'src/message.rs')
-rw-r--r--src/message.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/message.rs b/src/message.rs
index 63b1079..b37ba6b 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -3,7 +3,7 @@
use std::str::FromStr;
use std::string::{ ToString };
use std::borrow::{ ToOwned };
-use std::ops::Range;
+use std::ops::{ Deref, Range };
use ::IrscError;
@@ -39,7 +39,7 @@ impl Message {
}
#[allow(unused_assignments)]
- pub fn format(prefix: Option<&str>, command: &str, content: Vec<&str>, suffix: Option<&str>, msg_type: MsgType) -> Message {
+ pub fn format<T: Deref<Target=str>>(prefix: Option<T>, command: T, content: Vec<T>, suffix: Option<T>, msg_type: MsgType) -> Message {
let mut s = String::with_capacity(512);
let mut i = 0;
@@ -53,7 +53,7 @@ impl Message {
}
let i_command = i as u16..(i + command.len()) as u16;
- s.push_str(command);
+ s.push_str(&*command);
s.push(' ');
i += 1 + command.len();
@@ -90,6 +90,7 @@ impl Message {
pub fn command(&self) -> &str { self.range(&self.command) }
pub fn content(&self) -> Vec<&str> { self.content.iter().map(|r| self.range(&r)).collect() }
pub fn suffix(&self) -> Option<&str> { self.suffix.as_ref().map(|r| self.range(r)) }
+ pub fn elements(&self) -> Vec<&str> { let mut s = self.content(); self.suffix().map(|f| s.push(f)); s }
}
impl FromStr for Message {