diff --git a/src/stream.rs b/src/stream.rs index 9533eea..3c4cf32 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -4,7 +4,6 @@ use hidapi::HidApi; use rusb::UsbContext; use gilrs::{Gilrs, Button, Event}; use serde_json::json; -use handlebars::Handlebars; pub trait InputStream { fn get(&mut self) -> Vec; @@ -197,34 +196,23 @@ pub fn build_output_stream(cfg: &Stream) -> Box { return build_formatted_output_stream(cfg, _build_output_stream(cfg)) } -pub struct OutputStreamFormatted<'a> { - format: Option) -> Vec>>, +pub struct OutputStreamFormatted { + format: Box) -> Vec>, stream: Box, } pub fn build_formatted_output_stream(cfg: &Stream, stream: Box) -> Box { return Box::new(OutputStreamFormatted{ - format: match cfg.format.clone() { - Some(x) => { - let x = x.clone(); - Some(Box::new( - &|v: Vec| { - let mut reg = Handlebars::new(); - reg.register_template_string("x", x.clone()); - reg.render("x", &json!({"x": v})).unwrap().chars().collect() - }, - )) - }, - None => None, - }, + format: Box::new(|v: Vec| reg.render("x", &json!()).unwrap()), stream: stream, }); } -impl<'a> OutputStream for OutputStreamFormatted<'a> { +// TODO use https://crates.io/crates/handlebars instead +impl OutputStream for OutputStreamFormatted { fn put(&mut self, v: Vec) { match self.format.as_ref() { - Some(x) => self.stream.put(x(v)), + Some(x) => self.stream.put(sprintf(x, v)), None => self.stream.put(v), }; }