From ee96e7d79ef9e5505a2b7440cd5dc544da23540d Mon Sep 17 00:00:00 2001 From: Till Höppner Date: Sat, 23 Jan 2016 20:13:30 +0100 Subject: Restore full functionality --- src/format/binary.rs | 22 ++++++++++------------ src/format/mod.rs | 12 ++++++------ src/format/msgpack.rs | 22 ++++++++++------------ 3 files changed, 26 insertions(+), 30 deletions(-) (limited to 'src/format') diff --git a/src/format/binary.rs b/src/format/binary.rs index 367cdf9..a7ae7ca 100644 --- a/src/format/binary.rs +++ b/src/format/binary.rs @@ -14,7 +14,6 @@ use std::io::{ BufRead, Write }; use std::iter::Iterator; -use std::marker::PhantomData; use event::Event; use context::Context; @@ -24,29 +23,28 @@ use bincode::{ self, SizeLimit }; pub struct Binary; -pub struct Iter<'a, R: 'a> where R: BufRead { - _phantom: PhantomData<&'a ()>, - input: R +pub struct Iter<'a> { + input: &'a mut BufRead } -impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { +impl<'a> Iterator for Iter<'a> { type Item = ::Result>; fn next(&mut self) -> Option<::Result>> { - Some(bincode::rustc_serialize::decode_from::(&mut self.input, SizeLimit::Infinite) + Some(bincode::rustc_serialize::decode_from::<_, Event>(&mut self.input, SizeLimit::Infinite) .map_err(|_| ::IlcError::BincodeDecode)) } } -impl<'a, W> Encode<'a, W> for Binary where W: Write { - fn encode(&'a self, _context: &'a Context, mut output: W, event: &'a Event) -> ::Result<()> { +impl Encode for Binary { + fn encode<'a>(&'a self, _context: &'a Context, mut output: &'a mut Write, event: &'a Event) -> ::Result<()> { bincode::rustc_serialize::encode_into(event, &mut output, SizeLimit::Infinite) .map_err(|_| ::IlcError::BincodeEncode) } } -impl<'a, R: 'a> Decode<'a, R> for Binary where R: BufRead { - type Output = Iter<'a, R>; - fn decode(&'a mut self, _context: &'a Context, input: R) -> Iter { - Iter { _phantom: PhantomData, input: input } +impl Decode for Binary { + fn decode<'a>(&'a mut self, _context: &'a Context, input: &'a mut BufRead) + -> Box>> + 'a> { + Box::new(Iter { input: input }) } } diff --git a/src/format/mod.rs b/src/format/mod.rs index 370a92b..ff3a328 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -25,8 +25,8 @@ use context::Context; pub mod energymech; pub mod weechat3; -//pub mod binary; -//pub mod msgpack; +pub mod binary; +pub mod msgpack; pub trait Encode { fn encode<'a>(&'a self, context: &'a Context, output: &'a mut Write, event: &'a Event) -> ::Result<()>; @@ -48,8 +48,8 @@ pub fn decoder(format: &str) -> Option> { match format { "energymech" => Some(Box::new(energymech::Energymech)), "weechat3" => Some(Box::new(weechat3::Weechat3)), -// "binary" => Some(Box::new(binary::Binary)), -// "msgpack" => Some(Box::new(msgpack::Msgpack)), + "binary" => Some(Box::new(binary::Binary)), + "msgpack" => Some(Box::new(msgpack::Msgpack)), _ => None } } @@ -58,8 +58,8 @@ pub fn encoder(format: &str) -> Option> { match format { "energymech" => Some(Box::new(energymech::Energymech)), "weechat3" => Some(Box::new(weechat3::Weechat3)), -// "binary" => Some(Box::new(binary::Binary)), -// "msgpack" => Some(Box::new(msgpack::Msgpack)), + "binary" => Some(Box::new(binary::Binary)), + "msgpack" => Some(Box::new(msgpack::Msgpack)), _ => None } } diff --git a/src/format/msgpack.rs b/src/format/msgpack.rs index fb71b99..022e373 100644 --- a/src/format/msgpack.rs +++ b/src/format/msgpack.rs @@ -14,7 +14,6 @@ use std::io::{ BufRead, Write }; use std::iter::Iterator; -use std::marker::PhantomData; use event::Event; use context::Context; @@ -26,12 +25,11 @@ use rmp::decode::ReadError; pub struct Msgpack; -pub struct Iter<'a, R: 'a> where R: BufRead { - _phantom: PhantomData<&'a ()>, - input: R +pub struct Iter<'a> { + input: &'a mut BufRead } -impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { +impl<'a> Iterator for Iter<'a> { type Item = ::Result>; fn next(&mut self) -> Option<::Result>> { use msgpack::decode; @@ -43,16 +41,16 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { } } -impl<'a, W> Encode<'a, W> for Msgpack where W: Write { - fn encode(&'a self, _context: &'a Context, mut output: W, event: &'a Event) -> ::Result<()> { - event.encode(&mut Encoder::new(&mut output)) +impl Encode for Msgpack { + fn encode<'a>(&'a self, _context: &'a Context, output: &'a mut Write, event: &'a Event) -> ::Result<()> { + event.encode(&mut Encoder::new(output)) .map_err(|e| ::IlcError::MsgpackEncode(e)) } } -impl<'a, R: 'a> Decode<'a, R> for Msgpack where R: BufRead { - type Output = Iter<'a, R>; - fn decode(&'a mut self, _context: &'a Context, input: R) -> Iter { - Iter { _phantom: PhantomData, input: input } +impl Decode for Msgpack { + fn decode<'a>(&'a mut self, _context: &'a Context, input: &'a mut BufRead) + -> Box>> + 'a> { + Box::new(Iter { input: input }) } } -- cgit v1.2.3