summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-08 11:35:02 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-08 11:46:05 -0400
commitcb035e9de40b5b1e5a8a5e862ae9dd6a9da68d06 (patch)
treecb942997caf0ded2d4030d51e901a8579f3c45a4 /examples
parentcdf1047eb2c2d842006d7a117ad17845714ae004 (diff)
downloadrust-irc-cb035e9de40b5b1e5a8a5e862ae9dd6a9da68d06.tar.gz
rust-irc-cb035e9de40b5b1e5a8a5e862ae9dd6a9da68d06.zip
move the client implementation to a trait
this will allow us to more easily allow adding hooks
Diffstat (limited to 'examples')
-rw-r--r--examples/client.rs25
1 files changed, 24 insertions, 1 deletions
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<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 conn (&mut self) -> &mut io::BufferedStream<io::TcpStream> {
+ &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() {