From 08e2b1bf76f616b050cb3e10a892bc32ba5592db Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Thu, 23 Jul 2015 23:15:43 +0200 Subject: Functions to select a decoder/encoder based on a name --- src/format/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/format') 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>> { + 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>> { + 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), -- cgit v1.2.3