From f0e15804b4509ad57b6c13a380b81b0f0884ee68 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Mon, 10 Oct 2022 17:52:16 +0000 Subject: [PATCH] refactor(runtime): don't use From "the great thing about From is that you can from into from into from into from into and it's still the same. don't do that" Acked-by: cpli --- crates/oyster_runtime/src/pipeline.rs | 37 +++++++++++++-------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/crates/oyster_runtime/src/pipeline.rs b/crates/oyster_runtime/src/pipeline.rs index ae4a62c..f2ec863 100644 --- a/crates/oyster_runtime/src/pipeline.rs +++ b/crates/oyster_runtime/src/pipeline.rs @@ -34,6 +34,23 @@ struct PreparedCommand<'a> { } impl<'a> PreparedCommand<'a> { + /// Create a new PreparedCommand. + fn new(command: &'a ast::Command) -> Self { + let mut words = WordBuilder(command.0.iter()); + let cmd = words.next().expect("words need to have >1 parts"); + let args = words; + let redirect = command.1; + + PreparedCommand { + cmd, + args, + redirect, + stdin: None, + stdout: None, + stderr: None, + } + } + /// Run this command with the given context. fn spawn(self, pgid: &mut Pid) -> Result { let args = self.args.map(|w| match w { @@ -92,24 +109,6 @@ impl<'a> PreparedCommand<'a> { } } -impl<'a> From<&'a ast::Command<'a>> for PreparedCommand<'a> { - fn from(command: &'a ast::Command<'a>) -> Self { - let mut words = WordBuilder(command.0.iter()); - let cmd = words.next().expect("words need to have >1 parts"); - let args = words; - let redirect = command.1; - - PreparedCommand { - cmd, - args, - redirect, - stdin: None, - stdout: None, - stderr: None, - } - } -} - impl Shell { pub(crate) fn run_pipeline( &mut self, @@ -117,7 +116,7 @@ impl Shell { ) -> Result { let mut pgid = Pid::from_raw(0); let status = (|| { - let mut cmds = pipeline.0.iter().map(PreparedCommand::from); + let mut cmds = pipeline.0.iter().map(PreparedCommand::new); let mut last_cmd = cmds.next().expect("pipelines need to have >1 commands"); for mut cmd in cmds {