Implemented Display for Message.
This commit is contained in:
parent
e4495940fc
commit
863946ecb8
5 changed files with 11 additions and 4 deletions
|
@ -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.
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<String>);
|
||||
|
|
Loading…
Reference in a new issue