summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-08 12:31:27 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-08 12:31:27 -0400
commite41c5fa768cd006fc35ae14d7f6dec7912462161 (patch)
tree0399d5dc9e3a8b310474a5273a37f345534d9bd3 /examples
parent318259f54ee614d56aab0f434606a990645eee42 (diff)
downloadrust-irc-e41c5fa768cd006fc35ae14d7f6dec7912462161.tar.gz
rust-irc-e41c5fa768cd006fc35ae14d7f6dec7912462161.zip
start moving things into callbacks
Diffstat (limited to 'examples')
-rw-r--r--examples/client.rs22
1 files changed, 14 insertions, 8 deletions
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<ExampleClient>,
conn: io::BufferedStream<io::TcpStream>,
socket_name: Option<String>,
}
impl irc::Client for ExampleClient {
- fn new (conn: io::BufferedStream<io::TcpStream>, socket_name: Option<String>) -> ExampleClient {
- ExampleClient { conn: conn, socket_name: socket_name }
+ fn new (builder: irc::ClientBuilder<ExampleClient>, conn: io::BufferedStream<io::TcpStream>, socket_name: Option<String>) -> ExampleClient {
+ ExampleClient { builder: builder, conn: conn, socket_name: socket_name }
+ }
+ fn builder (&self) -> &irc::ClientBuilder<ExampleClient> {
+ &self.builder
}
fn conn (&mut self) -> &mut io::BufferedStream<io::TcpStream> {
&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();
}