aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTill Hoeppner2015-07-23 23:15:43 +0200
committerTill Hoeppner2015-07-23 23:15:43 +0200
commit08e2b1bf76f616b050cb3e10a892bc32ba5592db (patch)
treeef7b23d84122ddab66fafdce88ee0d41368a4d21 /src
parent96013802eb8cb8da86b5f6398e88375203cd5e28 (diff)
downloadilc-08e2b1bf76f616b050cb3e10a892bc32ba5592db.tar.gz
ilc-08e2b1bf76f616b050cb3e10a892bc32ba5592db.tar.xz
ilc-08e2b1bf76f616b050cb3e10a892bc32ba5592db.zip
Functions to select a decoder/encoder based on a name
Diffstat (limited to 'src')
-rw-r--r--src/format/mod.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/format/mod.rs b/src/format/mod.rs
index 2a36b34..cd849d5 100644
--- a/src/format/mod.rs
+++ b/src/format/mod.rs
@@ -48,6 +48,24 @@ impl<'a, T, I: BufRead> DecodeBox<'a, I> for T where T: Decode<'a, I> {
}
}
+pub fn decoder(format: &str) -> Option<Box<DecodeBox<&mut BufRead>>> {
+ match format {
+ "energymech" => Some(Box::new(energymech::Energymech)),
+ "weechat3" => Some(Box::new(weechat3::Weechat3)),
+ "binary" => Some(Box::new(binary::Binary)),
+ _ => None
+ }
+}
+
+pub fn encoder(format: &str) -> Option<Box<Encode<&mut Write>>> {
+ match format {
+ "energymech" => Some(Box::new(energymech::Energymech)),
+ "weechat3" => Some(Box::new(weechat3::Weechat3)),
+ "binary" => Some(Box::new(binary::Binary)),
+ _ => None
+ }
+}
+
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),