-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use std::process::ExitStatus; | ||
use crate::process::ExitStatus; | ||
|
||
use thiserror::Error; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use color_eyre::Result; | ||
use std::ops::{Deref, DerefMut}; | ||
use std::process; | ||
use std::process::{Child, Command}; | ||
use std::time; | ||
|
||
pub fn spawn(cmd: &mut Command) -> Result<Process> { | ||
Ok(Process { | ||
proc: cmd.spawn()?, | ||
instant: time::Instant::now(), | ||
}) | ||
} | ||
|
||
pub struct Process { | ||
proc: Child, | ||
instant: time::Instant, | ||
} | ||
|
||
impl Process { | ||
pub fn wait(&mut self) -> Result<ExitStatus> { | ||
let status = self.proc.wait()?; | ||
|
||
Ok(ExitStatus { | ||
status, | ||
elapsed: self.instant.elapsed(), | ||
}) | ||
} | ||
} | ||
|
||
impl Deref for Process { | ||
type Target = Child; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.proc | ||
} | ||
} | ||
|
||
impl DerefMut for Process { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.proc | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub struct ExitStatus { | ||
pub status: process::ExitStatus, | ||
elapsed: time::Duration, | ||
} | ||
|
||
impl ExitStatus { | ||
pub fn elapsed(&self) -> time::Duration { | ||
self.elapsed | ||
} | ||
} | ||
|
||
impl Deref for ExitStatus { | ||
type Target = process::ExitStatus; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.status | ||
} | ||
} | ||
|
||
impl DerefMut for ExitStatus { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.status | ||
} | ||
} |