From 19a778d004de584a09fa1d4c6c4bd8803ca80048 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Thu, 11 Jun 2015 12:39:45 +0200 Subject: Some inbetween state of confusion --- src/format/binary.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/format/binary.rs') diff --git a/src/format/binary.rs b/src/format/binary.rs index e8d880f..df57781 100644 --- a/src/format/binary.rs +++ b/src/format/binary.rs @@ -14,35 +14,38 @@ use std::io::{ BufRead, Write }; use std::iter::Iterator; +use std::marker::PhantomData; -use log::Event; +use event::Event; +use context::Context; use format::{ Encode, Decode }; use bincode::{ self, SizeLimit }; pub struct Binary; -pub struct Iter where R: BufRead { +pub struct Iter<'a, R: 'a> where R: BufRead { + _phantom: PhantomData<&'a ()>, input: R } -impl Iterator for Iter where R: BufRead { - type Item = ::Result; - fn next(&mut self) -> Option<::Result> { +impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { + type Item = ::Result>; + fn next(&mut self) -> Option<::Result>> { Some(bincode::decode_from::(&mut self.input, SizeLimit::Infinite) .map_err(|_| ::IlcError::BincodeDecode)) } } -impl Encode for Binary where W: Write { - fn encode(&self, mut output: W, event: &Event) -> ::Result<()> { +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<()> { bincode::encode_into(event, &mut output, SizeLimit::Infinite) .map_err(|_| ::IlcError::BincodeEncode) } } -impl Decode> for Binary where R: BufRead { - fn decode(&mut self, input: R) -> Iter { - Iter { input: input } +impl<'a, R: 'a> Decode<'a, R, Iter<'a, R>> for Binary where R: BufRead { + fn decode(&'a mut self, context: &'a Context, input: R) -> Iter { + Iter { _phantom: PhantomData, input: input } } } -- cgit v1.2.3