pub struct CommandWrap { /* private fields */ }tokio1 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 receives the newly registered wrapper
through its typed extend hook and can merge its configuration. If the hook does
nothing, the new wrapper is 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 native-child spawner function.
This is like spawn, but instead of calling command.spawn()
directly, it calls the provided closure to create the native child process. This is
useful when you need to use a platform-specific spawning mechanism that still returns
a Child.
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 spawn_with_child(
&mut self,
spawner: impl FnOnce(&mut Command) -> Result<Box<dyn ChildWrapper>>,
) -> Result<Box<dyn ChildWrapper>>
pub fn spawn_with_child( &mut self, spawner: impl FnOnce(&mut Command) -> Result<Box<dyn ChildWrapper>>, ) -> Result<Box<dyn ChildWrapper>>
Spawn the command using a custom boxed-child spawner function.
This is the spawning path for custom child implementations which do not return the
native Child type. The closure must return a boxed ChildWrapper trait object.
All pre_spawn hooks run first, then the provided closure is called, then
wrap_child hooks are applied. post_spawn is intentionally skipped because that
hook requires a native Child. Use spawn_with when the spawner returns one.
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. While a wrapper’s lifecycle hook is
running, that active wrapper remains registered but is temporarily unavailable through
this method; peer wrappers remain available. To merely check registration, use
has_wrap instead.