diff options
author | Till Hoeppner | 2015-07-23 23:15:43 +0200 |
---|---|---|
committer | Till Hoeppner | 2015-07-23 23:15:43 +0200 |
commit | 08e2b1bf76f616b050cb3e10a892bc32ba5592db (patch) | |
tree | ef7b23d84122ddab66fafdce88ee0d41368a4d21 /src/format/mod.rs | |
parent | 96013802eb8cb8da86b5f6398e88375203cd5e28 (diff) | |
download | ilc-08e2b1bf76f616b050cb3e10a892bc32ba5592db.tar.gz ilc-08e2b1bf76f616b050cb3e10a892bc32ba5592db.tar.xz ilc-08e2b1bf76f616b050cb3e10a892bc32ba5592db.zip |
Functions to select a decoder/encoder based on a name
Diffstat (limited to 'src/format/mod.rs')
-rw-r--r-- | src/format/mod.rs | 18 |
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), |