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