use std::borrow::Borrow;
use std::fmt::Debug;
#[cfg(doc)]
use std::process::Child;
#[cfg(doc)]
use std::process::Command;
#[cfg(doc)]
use crate::ChildExt;
use crate::CommandDisplay;
#[cfg(doc)]
use crate::OutputContext;
pub struct ChildContext<C> {
pub(crate) child: C,
pub(crate) command: Box<dyn CommandDisplay>,
}
impl<C> ChildContext<C> {
pub fn into_child(self) -> C {
self.child
}
pub fn child(&self) -> &C {
&self.child
}
pub fn child_mut(&mut self) -> &mut C {
&mut self.child
}
pub fn command(&self) -> &dyn CommandDisplay {
self.command.borrow()
}
}
impl<C> Debug for ChildContext<C>
where
C: Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ChildContext")
.field("child", &self.child)
.field("command", &self.command.to_string())
.finish()
}
}