diff --git a/src/processor.rs b/src/processor.rs index dc2ac06..75f4870 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -163,98 +163,6 @@ impl Processor for Blur { } } -trait Process { - fn path(&self, path: PathBuf) -> PathBuf; - - fn command(&self, args: Vec) -> Vec; - - fn len(&self, len: u64) -> u64; -} - -#[derive(Debug)] -struct Base; - -#[derive(Debug)] -struct ProcessorNode { - inner: Inner, - processor: P, -} - -impl ProcessorNode -where - P: Processor, -{ - fn new(inner: Inner, processor: P) -> Self { - ProcessorNode { inner, processor } - } -} - -impl Process for Base { - fn path(&self, path: PathBuf) -> PathBuf { - path - } - - fn command(&self, args: Vec) -> Vec { - args - } - - fn len(&self, len: u64) -> u64 { - len - } -} - -impl Process for ProcessorNode -where - Inner: Process, - P: Processor, -{ - fn path(&self, path: PathBuf) -> PathBuf { - self.processor.path(self.inner.path(path)) - } - - fn command(&self, args: Vec) -> Vec { - self.processor.command(self.inner.command(args)) - } - - fn len(&self, len: u64) -> u64 { - self.inner.len(len + 1) - } -} - -struct ProcessChain

{ - inner: P, -} - -impl

ProcessChain

-where - P: Process, -{ - fn len(&self) -> u64 { - self.inner.len(0) - } - - fn command(&self) -> Vec { - self.inner.command(vec![]) - } - - fn path(&self) -> PathBuf { - self.inner.path(PathBuf::new()) - } -} - -impl

std::fmt::Debug for ProcessChain

-where - P: Process, -{ - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.debug_struct("ProcessChain") - .field("path", &self.path()) - .field("command", &self.command()) - .field("steps", &self.len()) - .finish() - } -} - #[instrument] pub(crate) fn build_chain(args: &[(String, String)], filename: String) -> (PathBuf, Vec) { fn parse(key: &str, value: &str) -> Option

{ @@ -269,7 +177,7 @@ pub(crate) fn build_chain(args: &[(String, String)], filename: String) -> (PathB ($inner:expr, $args:expr, $filename:expr, $x:ident, $k:expr, $v:expr) => {{ if let Some(processor) = parse::<$x>($k, $v) { return build( - ProcessorNode::new($inner, processor), + (processor.path($inner.0), processor.command($inner.1)), &$args[1..], $filename, ); @@ -278,16 +186,12 @@ pub(crate) fn build_chain(args: &[(String, String)], filename: String) -> (PathB } fn build( - inner: impl Process, + inner: (PathBuf, Vec), args: &[(String, String)], filename: String, ) -> (PathBuf, Vec) { if args.len() == 0 { - let chain = ProcessChain { inner }; - - debug!("built: {:?}", chain); - - return (chain.path().join(filename), chain.command()); + return inner; } let (name, value) = &args[0]; @@ -303,7 +207,7 @@ pub(crate) fn build_chain(args: &[(String, String)], filename: String) -> (PathB build(inner, &args[1..], filename) } - build(Base, args, filename) + build((PathBuf::default(), vec![]), args, filename) } fn is_motion(s: &str) -> bool {