pub trait CommandWrapper:
Debug
+ Send
+ Sync {
// Provided methods
fn extend(&mut self, _other: Self)
where Self: Sized { ... }
fn pre_spawn(
&mut self,
_command: &mut Command,
_core: &CommandWrap,
) -> Result<()> { ... }
fn post_spawn(
&mut self,
_command: &mut Command,
_child: &mut Child,
_core: &CommandWrap,
) -> Result<()> { ... }
fn wrap_child(
&mut self,
child: Box<dyn ChildWrapper>,
_core: &CommandWrap,
) -> Result<Box<dyn ChildWrapper>> { ... }
}std only.Expand description
A trait for adding functionality to a Command.
This trait provides extension or hook points into the lifecycle of a Command. See the
crate-level doc for an overview.
All methods are optional, so a minimal impl may be:
#[derive(Debug)]
pub struct YourWrapper;
impl CommandWrapper for YourWrapper {}Provided Methods§
Sourcefn extend(&mut self, _other: Self)where
Self: Sized,
fn extend(&mut self, _other: Self)where
Self: Sized,
Called on a first instance if a second of the same type is added.
Only one wrapper of a given type can exist within a Wrap at a time. By default, later registrations are discarded. In some cases it is useful to merge their configuration instead. This method is called on the stored wrapper with the newly registered wrapper of the same concrete type.
Because other is Self, implementations can inspect or move its type-specific
fields directly without downcasting.
Default impl: no-op.
Sourcefn pre_spawn(
&mut self,
_command: &mut Command,
_core: &CommandWrap,
) -> Result<()>
fn pre_spawn( &mut self, _command: &mut Command, _core: &CommandWrap, ) -> Result<()>
Called before the command is spawned, to mutate it as needed.
This is where to modify the command before it is spawned. It also gives mutable
access to the wrapper instance, so state can be stored if needed. The core
reference gives access to data from other wrappers; for example, that’s how
CreationFlags on Windows works along with JobObject.
Defaut impl: no-op.
Sourcefn post_spawn(
&mut self,
_command: &mut Command,
_child: &mut Child,
_core: &CommandWrap,
) -> Result<()>
fn post_spawn( &mut self, _command: &mut Command, _child: &mut Child, _core: &CommandWrap, ) -> Result<()>
Called after spawn, but before the child is wrapped.
The core reference gives access to data from other wrappers; for example, that’s
how CreationFlags on Windows works along with JobObject.
Default: no-op.
Sourcefn wrap_child(
&mut self,
child: Box<dyn ChildWrapper>,
_core: &CommandWrap,
) -> Result<Box<dyn ChildWrapper>>
fn wrap_child( &mut self, child: Box<dyn ChildWrapper>, _core: &CommandWrap, ) -> Result<Box<dyn ChildWrapper>>
Called to wrap a child into this command wrapper’s child wrapper.
If the wrapper needs to override the methods on Child, then it should create an
instance of its own type implementing ChildWrapper and return it here. Child wraps
are in order: you may end up with a Foo(Bar(Child)) or a Bar(Foo(Child))
depending on if .wrap(Foo).wrap(Bar) or .wrap(Bar).wrap(Foo) was called.
The core reference gives access to data from other wrappers; for example, that’s
how CreationFlags on Windows works along with JobObject.
Default: no-op (ie, returns the child unchanged).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl CommandWrapper for ProcessGroup
process-group only.impl CommandWrapper for ProcessSession
process-session only.impl CommandWrapper for ResetSigmask
reset-sigmask only.