aboutsummaryrefslogtreecommitdiff
path: root/src/format/binary.rs
diff options
context:
space:
mode:
authorTill Höppner2015-06-11 20:57:39 +0200
committerTill Höppner2015-06-11 20:57:39 +0200
commitbc755a4dedc520b672bc7168ff6ef9d088072d99 (patch)
tree52bed0ed50693bb9f5bbdc52fa81d7e1edfb855c /src/format/binary.rs
parent86fe3230866082d6207eb5253f2e89623b941f63 (diff)
parentccc9f5e8eaa84579da610ea0d90d18596078bac7 (diff)
downloadilc-bc755a4dedc520b672bc7168ff6ef9d088072d99.tar.gz
ilc-bc755a4dedc520b672bc7168ff6ef9d088072d99.tar.xz
ilc-bc755a4dedc520b672bc7168ff6ef9d088072d99.zip
Merge pull request #1 from tilpner/cows
Update Event API with Option and Cow
Diffstat (limited to 'src/format/binary.rs')
-rw-r--r--src/format/binary.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/format/binary.rs b/src/format/binary.rs
index e8d880f..4c2e151 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<R> where R: BufRead {
+pub struct Iter<'a, R: 'a> where R: BufRead {
+ _phantom: PhantomData<&'a ()>,
input: R
}
-impl<R> Iterator for Iter<R> where R: BufRead {
- type Item = ::Result<Event>;
- fn next(&mut self) -> Option<::Result<Event>> {
+impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead {
+ type Item = ::Result<Event<'a>>;
+ fn next(&mut self) -> Option<::Result<Event<'a>>> {
Some(bincode::decode_from::<R, Event>(&mut self.input, SizeLimit::Infinite)
.map_err(|_| ::IlcError::BincodeDecode))
}
}
-impl<W> Encode<W> 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<R> Decode<R, Iter<R>> for Binary where R: BufRead {
- fn decode(&mut self, input: R) -> Iter<R> {
- 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<R> {
+ Iter { _phantom: PhantomData, input: input }
}
}