pub struct CommandWrap { /* 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 CommandWrap
impl CommandWrap
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 CommandWrap.
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: CommandWrapper + 'static>(&mut self, wrapper: W) -> &mut Self
pub fn wrap<W: CommandWrapper + '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 ChildWrapper>>
pub fn spawn(&mut self) -> Result<Box<dyn ChildWrapper>>
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_childs. 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 spawn_with(
&mut self,
spawner: impl FnOnce(&mut Command) -> Result<Child>,
) -> Result<Box<dyn ChildWrapper>>
pub fn spawn_with( &mut self, spawner: impl FnOnce(&mut Command) -> Result<Child>, ) -> Result<Box<dyn ChildWrapper>>
Spawn the command using a custom spawner function.
This is like spawn, but instead of calling command.spawn()
directly, it calls the provided closure to create the child process. This is
useful when you need to use a platform-specific or custom spawning mechanism.
The lifecycle is the same as spawn: all pre_spawn hooks run first, then
the provided closure is called, then post_spawn hooks, then wrap_child.
Sourcepub fn has_wrap<W: CommandWrapper + 'static>(&self) -> bool
pub fn has_wrap<W: CommandWrapper + 'static>(&self) -> bool
Check if a wrapper of a given type is present.
Sourcepub fn get_wrap<W: CommandWrapper + 'static>(&self) -> Option<&W>
pub fn get_wrap<W: CommandWrapper + '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.