diff options
author | Till Höppner | 2016-02-23 17:00:53 +0100 |
---|---|---|
committer | Till Höppner | 2016-02-24 18:36:04 +0100 |
commit | f01c278a26e0f248d188c10bdb852b0859b98b3b (patch) | |
tree | 3e729bf243011111a20b84f24aea3fbcb9f595f5 /src/format/mod.rs | |
parent | 815f31f5cef61709c50087c9f7601ea330929bb7 (diff) | |
download | ilc-f01c278a26e0f248d188c10bdb852b0859b98b3b.tar.gz ilc-f01c278a26e0f248d188c10bdb852b0859b98b3b.tar.xz ilc-f01c278a26e0f248d188c10bdb852b0859b98b3b.zip |
Test CI
Diffstat (limited to 'src/format/mod.rs')
-rw-r--r-- | src/format/mod.rs | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/format/mod.rs b/src/format/mod.rs index cea6855..8873db8 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -17,7 +17,7 @@ //! target format, all formats must allow for omittable information. use std::iter; -use std::io::{ BufRead, Write }; +use std::io::{BufRead, Write}; use std::borrow::Cow; use event::Event; @@ -35,17 +35,27 @@ mod binary; mod msgpack; pub trait Encode { - fn encode<'a>(&'a self, context: &'a Context, output: &'a mut Write, event: &'a Event) -> ::Result<()>; + fn encode<'a>(&'a self, + context: &'a Context, + output: &'a mut Write, + event: &'a Event) + -> ::Result<()>; } pub trait Decode { - fn decode<'a>(&'a mut self, context: &'a Context, input: &'a mut BufRead) -> Box<Iterator<Item = ::Result<Event<'a>>> + 'a>; + fn decode<'a>(&'a mut self, + context: &'a Context, + input: &'a mut BufRead) + -> Box<Iterator<Item = ::Result<Event<'a>>> + 'a>; } pub struct Dummy; impl Decode for Dummy { - fn decode<'a>(&'a mut self, _context: &'a Context, _input: &'a mut BufRead) -> Box<Iterator<Item = ::Result<Event<'a>>> + 'a> { + fn decode<'a>(&'a mut self, + _context: &'a Context, + _input: &'a mut BufRead) + -> Box<Iterator<Item = ::Result<Event<'a>>> + 'a> { Box::new(iter::empty()) } } @@ -54,10 +64,10 @@ pub fn decoder(format: &str) -> Option<Box<Decode>> { match format { "energymech" | "em" => Some(Box::new(Energymech)), "weechat" | "w" => Some(Box::new(Weechat)), -// "irssi" => Some(Box::new(irssi::Irssi)), + // "irssi" => Some(Box::new(irssi::Irssi)), "binary" => Some(Box::new(Binary)), "msgpack" => Some(Box::new(Msgpack)), - _ => None + _ => None, } } @@ -65,18 +75,24 @@ pub fn encoder(format: &str) -> Option<Box<Encode>> { match format { "energymech" | "em" => Some(Box::new(Energymech)), "weechat" | "w" => Some(Box::new(Weechat)), -// "irssi" => Some(Box::new(irssi::Irssi)), + // "irssi" => Some(Box::new(irssi::Irssi)), "binary" => Some(Box::new(Binary)), "msgpack" => Some(Box::new(Msgpack)), - _ => None + _ => None, } } fn rejoin(s: &[&str], splits: &[char]) -> Cow<'static, str> { let len = s.iter().map(|s| s.len()).fold(0, |a, b| a + b); - 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) + 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 { |