pub struct StdCommandWrap { /* private fields */ }
std
only.Expand description
A wrapper around a Command
that allows for additional functionality to be added.
This is the core type of the process-wrap
crate. It is a wrapper around a
Command
.
Implementations§
Source§impl StdCommandWrap
impl StdCommandWrap
Sourcepub fn with_new(
program: impl AsRef<OsStr>,
init: impl FnOnce(&mut Command),
) -> Self
pub fn with_new( program: impl AsRef<OsStr>, init: impl FnOnce(&mut Command), ) -> Self
Create from a program name and a closure to configure the command.
This is a convenience method that creates a new Command
and then calls the closure
to configure it. The Command
is then wrapped and returned.
Alternatively, use From
/Into
to convert a Command
to a StdCommandWrap
.
Sourcepub fn command_mut(&mut self) -> &mut Command
pub fn command_mut(&mut self) -> &mut Command
Get a mutable reference to the wrapped command.
Sourcepub fn into_command(self) -> Command
pub fn into_command(self) -> Command
Get the wrapped command.
Sourcepub fn wrap<W: StdCommandWrapper + 'static>(&mut self, wrapper: W) -> &mut Self
pub fn wrap<W: StdCommandWrapper + 'static>(&mut self, wrapper: W) -> &mut Self
Add a wrapper to the command.
This is a lazy method, and the wrapper is not actually applied until spawn
is
called.
Only one wrapper of a given type can be applied to a command. If wrap
is called
twice with the same type, the existing wrapper will have its extend
hook called,
which gives it a chance to absorb the new wrapper. If it does not, the new wrapper
will be silently discarded.
Returns &mut self
for chaining.
Sourcepub fn spawn(&mut self) -> Result<Box<dyn StdChildWrapper>>
pub fn spawn(&mut self) -> Result<Box<dyn StdChildWrapper>>
Spawn the command, returning a Child
that can be interacted with.
In order, this runs all the pre_spawn
hooks, then spawns the command, then runs
all the post_spawn
hooks, then stacks all the wrap_child
s. As it returns a boxed
trait object, only the methods from the trait are available directly; however you
may downcast to the concrete type of the last applied wrapper if you need to.
Sourcepub fn has_wrap<W: StdCommandWrapper + 'static>(&self) -> bool
pub fn has_wrap<W: StdCommandWrapper + 'static>(&self) -> bool
Check if a wrapper of a given type is present.
Sourcepub fn get_wrap<W: StdCommandWrapper + 'static>(&self) -> Option<&W>
pub fn get_wrap<W: StdCommandWrapper + 'static>(&self) -> Option<&W>
Get a reference to a wrapper of a given type.
This is useful for getting access to the state of a wrapper, generally from within another wrapper.
Returns None
if the wrapper is not present. To merely check if a wrapper is
present, use has_wrap
instead.