From cb035e9de40b5b1e5a8a5e862ae9dd6a9da68d06 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 8 Sep 2014 11:35:02 -0400 Subject: move the client implementation to a trait this will allow us to more easily allow adding hooks --- examples/client.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/client.rs b/examples/client.rs index cf9f328..eb3d31a 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -1,10 +1,33 @@ extern crate irc; use irc::constants::{Ping, Pong}; +use irc::Client; + +use std::io; + +struct ExampleClient { + conn: io::BufferedStream, + socket_name: Option, +} + +impl irc::Client for ExampleClient { + fn new (conn: io::BufferedStream, socket_name: Option) -> ExampleClient { + ExampleClient { conn: conn, socket_name: socket_name } + } + fn conn (&mut self) -> &mut io::BufferedStream { + &mut self.conn + } + fn socket_name (&self) -> Option<&str> { + match self.socket_name { + Some(ref name) => Some(name.as_slice()), + None => None, + } + } +} fn main () { let builder = irc::ClientBuilder::new("doytest", "chat.freenode.net"); - let client = builder.connect(); + let client: ExampleClient = builder.connect(); client.run_loop_with(|client, m| { println!("{}", m); match *m.message_type() { -- cgit v1.2.3