From 863946ecb808339671e2b77497e19a8d0976c8ef Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Thu, 17 Mar 2016 21:39:58 -0400 Subject: [PATCH] Implemented Display for Message. --- examples/multithreaded.rs | 2 +- examples/simple.rs | 2 +- examples/simple_ssl.rs | 2 +- examples/tweeter.rs | 2 +- src/client/data/message.rs | 7 +++++++ 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index fd84343..7edc889 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -16,7 +16,7 @@ fn main() { let server = server.clone(); let _ = spawn(move || { for msg in server.iter() { - print!("{}", msg.unwrap().to_string()); + print!("{}", msg.unwrap()); } }).join(); // You might not want to join here for actual multi-threading. } diff --git a/examples/simple.rs b/examples/simple.rs index ec0c187..b983755 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -15,7 +15,7 @@ fn main() { server.identify().unwrap(); for message in server.iter() { let message = message.unwrap(); // We'll just panic if there's an error. - print!("{}", message.to_string()); + print!("{}", message); match message.command { Command::PRIVMSG(ref target, ref msg) => if msg.contains("pickles") { server.send_privmsg(target, "Hi!").unwrap(); diff --git a/examples/simple_ssl.rs b/examples/simple_ssl.rs index ac02f77..0b2b898 100644 --- a/examples/simple_ssl.rs +++ b/examples/simple_ssl.rs @@ -16,7 +16,7 @@ fn main() { server.identify().unwrap(); for message in server.iter() { let message = message.unwrap(); // We'll just panic if there's an error. - print!("{}", message.to_string()); + print!("{}", message); match message.command { Command::PRIVMSG(ref target, ref msg) => if msg.contains("pickles") { server.send_privmsg(target, "Hi!").unwrap(); diff --git a/examples/tweeter.rs b/examples/tweeter.rs index e26944e..15dc76a 100644 --- a/examples/tweeter.rs +++ b/examples/tweeter.rs @@ -17,7 +17,7 @@ fn main() { let server2 = server.clone(); // Let's set up a loop that just prints the messages. spawn(move || { - server2.iter().map(|m| print!("{}", m.unwrap().to_string())).count(); + server2.iter().map(|m| print!("{}", m.unwrap())).count(); }); loop { server.send_privmsg("#vana", "TWEET TWEET").unwrap(); diff --git a/src/client/data/message.rs b/src/client/data/message.rs index 51eb178..ee26669 100644 --- a/src/client/data/message.rs +++ b/src/client/data/message.rs @@ -1,5 +1,6 @@ //! Messages to and from the server. use std::borrow::ToOwned; +use std::fmt::{Display, Formatter, Result as FmtResult}; use std::io::{Result as IoResult}; use std::str::FromStr; use client::data::Command; @@ -119,6 +120,12 @@ impl<'a> From<&'a str> for Message { } } +impl Display for Message { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + write!(f, "{}", self.to_string()) + } +} + /// A message tag as defined by [IRCv3.2](http://ircv3.net/specs/core/message-tags-3.2.html). #[derive(Clone, PartialEq, Debug)] pub struct Tag(String, Option);