From e41c5fa768cd006fc35ae14d7f6dec7912462161 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 8 Sep 2014 12:31:27 -0400 Subject: start moving things into callbacks --- examples/client.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/client.rs b/examples/client.rs index 6696460..4da1220 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -6,13 +6,17 @@ use irc::Client; use std::io; struct ExampleClient { + builder: irc::ClientBuilder, 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 new (builder: irc::ClientBuilder, conn: io::BufferedStream, socket_name: Option) -> ExampleClient { + ExampleClient { builder: builder, conn: conn, socket_name: socket_name } + } + fn builder (&self) -> &irc::ClientBuilder { + &self.builder } fn conn (&mut self) -> &mut io::BufferedStream { &mut self.conn @@ -23,12 +27,8 @@ impl irc::Client for ExampleClient { None => None, } } -} -fn main () { - let builder = irc::ClientBuilder::new("doytest", "chat.freenode.net"); - let client: ExampleClient = builder.connect(); - client.run_loop_with(|client, m| { + fn on_message (client: &mut ExampleClient, m: irc::Message) { print!("{}", m.to_protocol_string()); match *m.message_type() { Ping => { @@ -36,5 +36,11 @@ fn main () { }, _ => {}, } - }); + } +} + +fn main () { + let builder = irc::ClientBuilder::new("doytest", "chat.freenode.net"); + let client: ExampleClient = builder.connect(); + client.run_loop(); } -- cgit v1.2.3-54-g00ecf