From 81b3e58d52c74b528ada068f4fc8a27e04813b02 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Fri, 5 Jun 2015 21:27:15 -0400 Subject: [PATCH] Replaced Command::from_message with a From<&Message> implementation. --- examples/autoreconnect.rs | 2 +- src/client/data/command.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/autoreconnect.rs b/examples/autoreconnect.rs index a31b5e9..0c0aba7 100644 --- a/examples/autoreconnect.rs +++ b/examples/autoreconnect.rs @@ -24,7 +24,7 @@ fn main() { match msg { Ok(msg) => { print!("{}", msg.into_string()); - match Command::from_message(&msg) { + match (&msg).into() { Ok(Command::PRIVMSG(_, msg)) => if msg.contains("bye") { server.send_quit("").unwrap() }, diff --git a/src/client/data/command.rs b/src/client/data/command.rs index f9a1cff..20d8879 100644 --- a/src/client/data/command.rs +++ b/src/client/data/command.rs @@ -348,9 +348,9 @@ fn string(s: &'static str) -> String { s.to_owned() } -impl Command { +impl<'a> From<&'a Message> for Result { /// Converts a Message into a Command. - pub fn from_message(m: &Message) -> Result { + fn from(m: &'a Message) -> Result { Ok(if let "PASS" = &m.command[..] { match m.suffix { Some(ref suffix) => { @@ -1102,10 +1102,12 @@ impl Command { return Err(invalid_input()) }) } +} +impl Command { /// Converts a potential Message result into a potential Command result. pub fn from_message_io(m: Result) -> Result { - m.and_then(|msg| Command::from_message(&msg)) + m.and_then(|msg| (&msg).into()) } }