command_error/
try_wait_context.rs1use std::borrow::Borrow;
2use std::fmt::Debug;
3use std::process::ExitStatus;
4
5#[cfg(doc)]
6use std::process::Child;
7#[cfg(doc)]
8use std::process::Command;
9
10use crate::CommandDisplay;
11use crate::OutputContext;
12
13pub struct TryWaitContext {
17 pub(crate) status: Option<ExitStatus>,
18 pub(crate) command: Box<dyn CommandDisplay + Send + Sync>,
19}
20
21impl TryWaitContext {
22 pub fn status(&self) -> Option<ExitStatus> {
24 self.status
25 }
26
27 pub fn command(&self) -> &(dyn CommandDisplay + Send + Sync) {
30 self.command.borrow()
31 }
32
33 pub fn into_command(self) -> Box<(dyn CommandDisplay + Send + Sync)> {
35 self.command
36 }
37
38 pub fn into_output_context(self) -> Option<OutputContext<ExitStatus>> {
40 self.status.map(|status| OutputContext {
41 output: status,
42 command: self.command,
43 })
44 }
45}
46
47impl Debug for TryWaitContext {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 f.debug_struct("TryWaitContext")
50 .field("status", &self.status)
51 .field("command", &self.command.to_string())
52 .finish()
53 }
54}