aboutsummaryrefslogtreecommitdiff
path: root/src/format/mod.rs
diff options
context:
space:
mode:
authorTill Hoeppner2015-07-23 22:57:43 +0200
committerTill Hoeppner2015-07-23 22:57:43 +0200
commit96013802eb8cb8da86b5f6398e88375203cd5e28 (patch)
treec6e7b69a84e52a59bfec2a14d49058dc185964ae /src/format/mod.rs
parenta4ed13e46fcef39d53126b3dc11d4f3705237b60 (diff)
downloadilc-96013802eb8cb8da86b5f6398e88375203cd5e28.tar.gz
ilc-96013802eb8cb8da86b5f6398e88375203cd5e28.tar.xz
ilc-96013802eb8cb8da86b5f6398e88375203cd5e28.zip
Support dynamic selection of decoders/encoders
Diffstat (limited to 'src/format/mod.rs')
-rw-r--r--src/format/mod.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/format/mod.rs b/src/format/mod.rs
index db86a1d..2a36b34 100644
--- a/src/format/mod.rs
+++ b/src/format/mod.rs
@@ -30,8 +30,22 @@ pub trait Encode<'a, W> where W: Write {
fn encode(&'a self, context: &'a Context, output: W, event: &'a Event) -> ::Result<()>;
}
-pub trait Decode<'a, R, O> where R: BufRead, O: Iterator<Item = ::Result<Event<'a>>> {
- fn decode(&'a mut self, context: &'a Context, input: R) -> O;
+pub trait Decode<'a, Input> where Input: BufRead,
+ Self::Output: Iterator<Item = ::Result<Event<'a>>> + 'a {
+ type Output;
+ fn decode(&'a mut self, context: &'a Context, input: Input) -> Self::Output;
+}
+
+pub trait DecodeBox<'a, I> {
+ fn decode_box(&'a mut self, context: &'a Context, input: I)
+ -> Box<Iterator<Item = ::Result<Event>> + 'a>;
+}
+
+impl<'a, T, I: BufRead> DecodeBox<'a, I> for T where T: Decode<'a, I> {
+ fn decode_box(&'a mut self, context: &'a Context, input: I)
+ -> Box<Iterator<Item = ::Result<Event>> + 'a> {
+ Box::new(self.decode(context, input))
+ }
}
fn rejoin(s: &[&str], splits: &[char]) -> Cow<'static, str> {