Replaced Command::from_message with a From<&Message> implementation.

This commit is contained in:
Aaron Weiss 2015-06-05 21:27:15 -04:00
parent f46f877605
commit 81b3e58d52
2 changed files with 6 additions and 4 deletions

View file

@ -24,7 +24,7 @@ fn main() {
match msg { match msg {
Ok(msg) => { Ok(msg) => {
print!("{}", msg.into_string()); print!("{}", msg.into_string());
match Command::from_message(&msg) { match (&msg).into() {
Ok(Command::PRIVMSG(_, msg)) => if msg.contains("bye") { Ok(Command::PRIVMSG(_, msg)) => if msg.contains("bye") {
server.send_quit("").unwrap() server.send_quit("").unwrap()
}, },

View file

@ -348,9 +348,9 @@ fn string(s: &'static str) -> String {
s.to_owned() s.to_owned()
} }
impl Command { impl<'a> From<&'a Message> for Result<Command> {
/// Converts a Message into a Command. /// Converts a Message into a Command.
pub fn from_message(m: &Message) -> Result<Command> { fn from(m: &'a Message) -> Result<Command> {
Ok(if let "PASS" = &m.command[..] { Ok(if let "PASS" = &m.command[..] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
@ -1102,10 +1102,12 @@ impl Command {
return Err(invalid_input()) return Err(invalid_input())
}) })
} }
}
impl Command {
/// Converts a potential Message result into a potential Command result. /// Converts a potential Message result into a potential Command result.
pub fn from_message_io(m: Result<Message>) -> Result<Command> { pub fn from_message_io(m: Result<Message>) -> Result<Command> {
m.and_then(|msg| Command::from_message(&msg)) m.and_then(|msg| (&msg).into())
} }
} }