use std::borrow::Borrow;
use std::fmt::Debug;
use std::process::ExitStatus;
#[cfg(doc)]
use std::process::Child;
#[cfg(doc)]
use std::process::Command;
use crate::CommandDisplay;
use crate::OutputContext;
pub struct TryWaitContext {
status: Option<ExitStatus>,
command: Box<dyn CommandDisplay + Send + Sync>,
}
impl TryWaitContext {
pub fn new(status: Option<ExitStatus>, command: Box<dyn CommandDisplay + Send + Sync>) -> Self {
Self { status, command }
}
pub fn status(&self) -> Option<ExitStatus> {
self.status
}
pub fn command(&self) -> &(dyn CommandDisplay + Send + Sync) {
self.command.borrow()
}
pub fn into_command(self) -> Box<(dyn CommandDisplay + Send + Sync)> {
self.command
}
pub fn into_output_context(self) -> Option<OutputContext<ExitStatus>> {
self.status
.map(|status| OutputContext::new(status, self.command))
}
}
impl Debug for TryWaitContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TryWaitContext")
.field("status", &self.status)
.field("command", &self.command.to_string())
.finish()
}
}