aboutsummaryrefslogtreecommitdiff
path: root/src/format/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/format/mod.rs')
-rw-r--r--src/format/mod.rs38
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 {