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/mod.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/format/mod.rs') diff --git a/src/format/mod.rs b/src/format/mod.rs index f5692a0..bc1e7df 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -17,16 +17,30 @@ //! target format, all formats must allow for omittable information. use std::io::{ BufRead, Write }; +use std::borrow::Cow; -use log::Event; +use event::Event; +use context::Context; pub mod weechat3; -pub mod binary; +//pub mod energymech; +//pub mod binary; -pub trait Encode where W: Write { - fn encode(&self, output: W, event: &Event) -> ::Result<()>; +pub trait Encode<'a, W> where W: Write { + fn encode(&'a self, context: &'a Context, output: W, event: &'a Event) -> ::Result<()>; } -pub trait Decode where R: BufRead, O: Iterator> { - fn decode(&mut self, input: R) -> O; +pub trait Decode<'a, R, O> where R: BufRead, O: Iterator>> { + fn decode(&'a mut self, context: &'a Context, input: R) -> O; +} + +fn rejoin(s: &[&str], splits: &[char]) -> Cow<'static, str> { + let len = s.iter().map(|s| s.len()).sum(); + let mut out = s.iter().zip(splits.iter()).fold(String::with_capacity(len), + |mut s, (b, &split)| { s.push_str(b); s.push(split); s }); + out.pop(); Cow::Owned(out) +} + +fn strip_one(s: &str) -> String { + if s.len() >= 2 { s[1..(s.len() - 1)].to_owned() } else { String::new() } } -- cgit v1.2.3 From 27e53e57777fac2fe47f1a2610d0122dc60ed97d Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Thu, 11 Jun 2015 18:28:44 +0200 Subject: Adapt energymech to new Event API --- src/format/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/format/mod.rs') diff --git a/src/format/mod.rs b/src/format/mod.rs index bc1e7df..e6c4897 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -23,7 +23,7 @@ use event::Event; use context::Context; pub mod weechat3; -//pub mod energymech; +pub mod energymech; //pub mod binary; pub trait Encode<'a, W> where W: Write { -- cgit v1.2.3 From 8361e508303d1573db7a0a5e892cfe2bdf42ffbb Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Thu, 11 Jun 2015 18:29:25 +0200 Subject: Re-enable binary --- src/format/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/format/mod.rs') diff --git a/src/format/mod.rs b/src/format/mod.rs index e6c4897..db86a1d 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -24,7 +24,7 @@ use context::Context; pub mod weechat3; pub mod energymech; -//pub mod binary; +pub mod binary; pub trait Encode<'a, W> where W: Write { fn encode(&'a self, context: &'a Context, output: W, event: &'a Event) -> ::Result<()>; -- cgit v1.2.3