From d64db47867cdd54cdc005333203436fce193c4fc Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 6 Sep 2014 18:39:51 -0400 Subject: pass in the client to callbacks this requires run_loop_with to consume the client, since we need to be able to pass it in mutably. i think that is probably okay. --- examples/client.rs | 5 +++-- src/client.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/client.rs b/examples/client.rs index f1f2479..ef0f7d2 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -1,8 +1,9 @@ extern crate irc; fn main () { - let mut client = irc::ClientBuilder::new("doytest", "chat.freenode.net").connect(); - client.run_loop_with(|m| { + let builder = irc::ClientBuilder::new("doytest", "chat.freenode.net"); + let client = builder.connect(); + client.run_loop_with(|_client, m| { println!("{}", m); }); } diff --git a/src/client.rs b/src/client.rs index 3beda7d..1623b02 100644 --- a/src/client.rs +++ b/src/client.rs @@ -140,9 +140,10 @@ impl Client { // storing closures very well yet if they need to receive a borrowed // pointer, and we would need to pass the client object into the callback // in order to make this work - pub fn run_loop_with (&mut self, handler: |Message|) { + pub fn run_loop_with (mut self, handler: |&mut Client, Message|) { loop { - handler(self.read()); + let m = self.read(); + handler(&mut self, m); } } } -- cgit v1.2.3