pub struct Process<NameState = Unnamed, StdoutConfig = Unset, Stdout = Unset, StderrConfig = Unset, Stderr = Unset> { /* private fields */ }Expand description
Typestate builder for configuring and spawning a process.
A process must be named before configuring output streams. This keeps public errors and tracing fields intentional, while stdout and stderr stream configuration remains explicit at the spawn call site.
§Examples
use tokio_process_tools::*;
use tokio_process_tools::SpawnError;
use tokio::process::Command;
let process = Process::new(Command::new("cargo"))
.name("test-runner")
.stdout_and_stderr(|stream| {
stream
.broadcast()
.best_effort_delivery()
.no_replay()
.read_chunk_size(DEFAULT_READ_CHUNK_SIZE)
.max_buffered_chunks(DEFAULT_MAX_BUFFERED_CHUNKS)
})
.spawn()?;Implementations§
Source§impl Process
impl Process
Sourcepub fn name(self, name: impl Into<ProcessName>) -> Process<Named>
pub fn name(self, name: impl Into<ProcessName>) -> Process<Named>
Sets how the process should be named.
You can provide either an explicit name or configure automatic name generation.
The name is used in public errors and tracing fields. By default, automatic
naming captures only the program name. Prefer .name(...) for stable safe
labels when command arguments or environment variables may contain secrets.
Source§impl Process<Named>
impl Process<Named>
Sourcepub fn stdout_and_stderr<Config, Stream>(
self,
configure: impl FnOnce(ProcessStreamBuilder) -> Config,
) -> Process<Named, Config, Stream, Config, Stream>
pub fn stdout_and_stderr<Config, Stream>( self, configure: impl FnOnce(ProcessStreamBuilder) -> Config, ) -> Process<Named, Config, Stream, Config, Stream>
Configures stdout and stderr with the same output stream settings.
Sourcepub fn stdout<StdoutConfig, Stdout>(
self,
configure: impl FnOnce(ProcessStreamBuilder) -> StdoutConfig,
) -> Process<Named, StdoutConfig, Stdout>where
StdoutConfig: ProcessStreamConfig<Stdout>,
Stdout: OutputStream,
pub fn stdout<StdoutConfig, Stdout>(
self,
configure: impl FnOnce(ProcessStreamBuilder) -> StdoutConfig,
) -> Process<Named, StdoutConfig, Stdout>where
StdoutConfig: ProcessStreamConfig<Stdout>,
Stdout: OutputStream,
Configures stdout before configuring stderr.
Sourcepub fn stderr<StderrConfig, Stderr>(
self,
configure: impl FnOnce(ProcessStreamBuilder) -> StderrConfig,
) -> Process<Named, Unset, Unset, StderrConfig, Stderr>where
StderrConfig: ProcessStreamConfig<Stderr>,
Stderr: OutputStream,
pub fn stderr<StderrConfig, Stderr>(
self,
configure: impl FnOnce(ProcessStreamBuilder) -> StderrConfig,
) -> Process<Named, Unset, Unset, StderrConfig, Stderr>where
StderrConfig: ProcessStreamConfig<Stderr>,
Stderr: OutputStream,
Configures stderr before configuring stdout.
Source§impl<StdoutConfig, Stdout> Process<Named, StdoutConfig, Stdout>where
Stdout: OutputStream,
impl<StdoutConfig, Stdout> Process<Named, StdoutConfig, Stdout>where
Stdout: OutputStream,
Sourcepub fn stderr<StderrConfig, Stderr>(
self,
configure: impl FnOnce(ProcessStreamBuilder) -> StderrConfig,
) -> Process<Named, StdoutConfig, Stdout, StderrConfig, Stderr>where
StdoutConfig: ProcessStreamConfig<Stdout>,
StderrConfig: ProcessStreamConfig<Stderr>,
Stderr: OutputStream,
pub fn stderr<StderrConfig, Stderr>(
self,
configure: impl FnOnce(ProcessStreamBuilder) -> StderrConfig,
) -> Process<Named, StdoutConfig, Stdout, StderrConfig, Stderr>where
StdoutConfig: ProcessStreamConfig<Stdout>,
StderrConfig: ProcessStreamConfig<Stderr>,
Stderr: OutputStream,
Configures stderr and completes the process builder.
Source§impl<StderrConfig, Stderr> Process<Named, Unset, Unset, StderrConfig, Stderr>where
Stderr: OutputStream,
impl<StderrConfig, Stderr> Process<Named, Unset, Unset, StderrConfig, Stderr>where
Stderr: OutputStream,
Sourcepub fn stdout<StdoutConfig, Stdout>(
self,
configure: impl FnOnce(ProcessStreamBuilder) -> StdoutConfig,
) -> Process<Named, StdoutConfig, Stdout, StderrConfig, Stderr>where
StderrConfig: ProcessStreamConfig<Stderr>,
StdoutConfig: ProcessStreamConfig<Stdout>,
Stdout: OutputStream,
pub fn stdout<StdoutConfig, Stdout>(
self,
configure: impl FnOnce(ProcessStreamBuilder) -> StdoutConfig,
) -> Process<Named, StdoutConfig, Stdout, StderrConfig, Stderr>where
StderrConfig: ProcessStreamConfig<Stderr>,
StdoutConfig: ProcessStreamConfig<Stdout>,
Stdout: OutputStream,
Configures stdout and completes the process builder.
Source§impl<StdoutConfig, Stdout, StderrConfig, Stderr> Process<Named, StdoutConfig, Stdout, StderrConfig, Stderr>where
Stdout: OutputStream,
Stderr: OutputStream,
impl<StdoutConfig, Stdout, StderrConfig, Stderr> Process<Named, StdoutConfig, Stdout, StderrConfig, Stderr>where
Stdout: OutputStream,
Stderr: OutputStream,
Sourcepub fn spawn(self) -> Result<ProcessHandle<Stdout, Stderr>, SpawnError>where
StdoutConfig: ProcessStreamConfig<Stdout>,
StderrConfig: ProcessStreamConfig<Stderr>,
pub fn spawn(self) -> Result<ProcessHandle<Stdout, Stderr>, SpawnError>where
StdoutConfig: ProcessStreamConfig<Stdout>,
StderrConfig: ProcessStreamConfig<Stderr>,
Spawns the process with the configured output streams.
§Errors
Returns SpawnError::SpawnFailed if the process cannot be spawned.