summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-09 14:52:39 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-09 14:52:39 -0400
commit0ed3107270494e6c780066a22f532941869e19f2 (patch)
treeab7b3f332561dd77253f20788e59c228e91140e2 /examples
parent2dc11043a4403e07c00bf9402e72dcf777f3a310 (diff)
downloadrust-irc-0ed3107270494e6c780066a22f532941869e19f2.tar.gz
rust-irc-0ed3107270494e6c780066a22f532941869e19f2.zip
move callbacks out to their own trait
this reduces the amount of things users have to worry about reimplementing, since we don't have associated items yet
Diffstat (limited to 'examples')
-rw-r--r--examples/client.rs35
1 files changed, 6 insertions, 29 deletions
diff --git a/examples/client.rs b/examples/client.rs
index 236b07e..5b874bb 100644
--- a/examples/client.rs
+++ b/examples/client.rs
@@ -1,38 +1,15 @@
extern crate irc;
use irc::constants::Pong;
-use irc::Client;
-use std::io;
+pub struct ExampleClient;
-struct ExampleClient {
- builder: irc::ClientBuilder<ExampleClient>,
- conn: io::BufferedStream<io::TcpStream>,
- socket_name: Option<String>,
-}
-
-impl irc::Client for ExampleClient {
- 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
- }
- fn socket_name (&self) -> Option<&str> {
- match self.socket_name {
- Some(ref name) => Some(name.as_slice()),
- None => None,
- }
- }
-
- fn on_any_message (_client: &mut ExampleClient, m: &irc::Message) {
+impl irc::ClientCallbacks for ExampleClient {
+ fn on_any_message (&mut self, _client: &mut irc::Client, m: &irc::Message) {
print!("{}", m.to_protocol_string());
}
- fn on_ping (client: &mut ExampleClient, _from: Option<&str>, server1: &str, server2: Option<&str>) {
+ fn on_ping (&mut self, client: &mut irc::Client, _from: Option<&str>, server1: &str, server2: Option<&str>) {
let params = match server2 {
Some(server2) => vec![server1.to_string(), server2.to_string()],
None => vec![server1.to_string()],
@@ -43,6 +20,6 @@ impl irc::Client for ExampleClient {
fn main () {
let builder = irc::ClientBuilder::new("doytest", "chat.freenode.net");
- let client: ExampleClient = builder.connect();
- client.run_loop();
+ let client = builder.connect();
+ client.run_loop_with_callbacks(ExampleClient);
}