diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-09-10 16:02:42 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-09-10 16:02:42 -0400 |
commit | 5bca38d9af67001ea6d406c1a447e7cc80a41e29 (patch) | |
tree | 14b22ddb5029ecf95a2855dd763c68082ca5e210 /src/client.rs | |
parent | b457ab74c224d65b64cfb46732a5b7b5e9bc554d (diff) | |
download | rust-irc-5bca38d9af67001ea6d406c1a447e7cc80a41e29.tar.gz rust-irc-5bca38d9af67001ea6d406c1a447e7cc80a41e29.zip |
move debug output into the library
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/client.rs b/src/client.rs index 04b2b0b..8f7ee6f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -19,6 +19,8 @@ pub struct ClientBuilder { servername: String, port: u16, + + debug: bool, } impl ClientBuilder { @@ -33,6 +35,8 @@ impl ClientBuilder { servername: servername.to_string(), port: 6667, + + debug: false, } } @@ -61,6 +65,11 @@ impl ClientBuilder { self } + pub fn set_debug (&mut self, debug: bool) -> &mut ClientBuilder { + self.debug = debug; + self + } + pub fn connect (self) -> Client { let stream = io::TcpStream::connect(self.servername.as_slice(), self.port); let mut stream = stream.unwrap(); @@ -116,13 +125,21 @@ impl Client { // XXX handle different encodings match Message::parse(String::from_utf8_lossy(buf.slice(0, len)).as_slice()) { - Ok(m) => Ok(m), + Ok(m) => { + if self.builder.debug { + print!("R {}", m.to_protocol_string()); + } + Ok(m) + }, Err(s) => Err(ParseError(s)), } } - pub fn write (&mut self, msg: Message) -> io::IoResult<()> { - try!(msg.write_protocol_string(self.conn())); + pub fn write (&mut self, m: Message) -> io::IoResult<()> { + try!(m.write_protocol_string(self.conn())); + if self.builder.debug { + print!("W {}", m.to_protocol_string()); + } Ok(()) } |