command_error/
child_context.rs1use std::borrow::Borrow;
2use std::fmt::Debug;
3
4#[cfg(doc)]
5use std::process::Child;
6#[cfg(doc)]
7use std::process::Command;
8
9#[cfg(doc)]
10use crate::ChildExt;
11use crate::CommandDisplay;
12#[cfg(doc)]
13use crate::OutputContext;
14
15pub struct ChildContext<C> {
21 pub(crate) child: C,
22 pub(crate) command: Box<dyn CommandDisplay + Send + Sync>,
23}
24
25impl<C> ChildContext<C> {
26 pub fn into_child(self) -> C {
28 self.child
29 }
30
31 pub fn child(&self) -> &C {
33 &self.child
34 }
35
36 pub fn child_mut(&mut self) -> &mut C {
38 &mut self.child
39 }
40
41 pub fn command(&self) -> &(dyn CommandDisplay + Send + Sync) {
43 self.command.borrow()
44 }
45}
46
47impl<C> Debug for ChildContext<C>
48where
49 C: Debug,
50{
51 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 f.debug_struct("ChildContext")
53 .field("child", &self.child)
54 .field("command", &self.command.to_string())
55 .finish()
56 }
57}