refactor(runtime): don't use From<ref>
"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
This commit is contained in:
parent
fe3d05d36b
commit
f0e15804b4
1 changed files with 18 additions and 19 deletions
|
@ -34,6 +34,23 @@ struct PreparedCommand<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> 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.
|
/// Run this command with the given context.
|
||||||
fn spawn(self, pgid: &mut Pid) -> Result<Child, RuntimeError> {
|
fn spawn(self, pgid: &mut Pid) -> Result<Child, RuntimeError> {
|
||||||
let args = self.args.map(|w| match w {
|
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 {
|
impl Shell {
|
||||||
pub(crate) fn run_pipeline(
|
pub(crate) fn run_pipeline(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -117,7 +116,7 @@ impl Shell {
|
||||||
) -> Result<Status, RuntimeError> {
|
) -> Result<Status, RuntimeError> {
|
||||||
let mut pgid = Pid::from_raw(0);
|
let mut pgid = Pid::from_raw(0);
|
||||||
let status = (|| {
|
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");
|
let mut last_cmd = cmds.next().expect("pipelines need to have >1 commands");
|
||||||
for mut cmd in cmds {
|
for mut cmd in cmds {
|
||||||
|
|
Loading…
Reference in a new issue