command : passage de la reference à self en mut dans le trait Command

This commit is contained in:
Ahurac 2024-04-11 01:34:15 +02:00
parent b06b0f1c15
commit 5f59139c3e

View file

@ -19,7 +19,7 @@ impl ExitCode {
} }
pub trait Command { pub trait Command {
fn spawn(&self) -> ExitCode; fn spawn(&mut self) -> ExitCode;
} }
pub struct CommandSequence { pub struct CommandSequence {
@ -46,11 +46,11 @@ impl CommandSequence {
} }
impl Command for CommandSequence { impl Command for CommandSequence {
fn spawn(&self) -> ExitCode { fn spawn(&mut self) -> ExitCode {
let mut exit_code = self.command.spawn(); let mut exit_code = self.command.spawn();
if self.next_command.is_some() { if self.next_command.is_some() {
exit_code = self.next_command.as_ref().unwrap().spawn(); exit_code = self.next_command.as_mut().unwrap().spawn();
} }
exit_code exit_code
@ -75,7 +75,13 @@ impl Command for UnixProgram {
let mut command = std::process::Command::new(&program); let mut command = std::process::Command::new(&program);
command.args(argv); command.args(argv);
let handle = command.spawn(); Self { command }
}
}
impl Command for UnixProgram {
fn spawn(&mut self) -> ExitCode {
let handle = self.command.spawn();
if handle.is_ok() { if handle.is_ok() {
let exit_code = handle let exit_code = handle