Skip to main content

Process

Struct Process 

Source
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

Source

pub fn new(cmd: Command) -> Self

Creates a new process builder from a tokio command.

Source

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>

Source

pub fn stdout_and_stderr<Config, Stream>( self, configure: impl FnOnce(ProcessStreamBuilder) -> Config, ) -> Process<Named, Config, Stream, Config, Stream>
where Config: ProcessStreamConfig<Stream> + Copy, Stream: OutputStream,

Configures stdout and stderr with the same output stream settings.

Source

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.

Source

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,

Source

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,

Source

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,

Source

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.

Auto Trait Implementations§

§

impl<NameState, StdoutConfig, Stdout, StderrConfig, Stderr> Freeze for Process<NameState, StdoutConfig, Stdout, StderrConfig, Stderr>
where NameState: Freeze, StdoutConfig: Freeze, StderrConfig: Freeze,

§

impl<NameState = Unnamed, StdoutConfig = Unset, Stdout = Unset, StderrConfig = Unset, Stderr = Unset> !RefUnwindSafe for Process<NameState, StdoutConfig, Stdout, StderrConfig, Stderr>

§

impl<NameState, StdoutConfig, Stdout, StderrConfig, Stderr> Send for Process<NameState, StdoutConfig, Stdout, StderrConfig, Stderr>
where NameState: Send, StdoutConfig: Send, StderrConfig: Send,

§

impl<NameState, StdoutConfig, Stdout, StderrConfig, Stderr> Sync for Process<NameState, StdoutConfig, Stdout, StderrConfig, Stderr>
where NameState: Sync, StdoutConfig: Sync, StderrConfig: Sync,

§

impl<NameState, StdoutConfig, Stdout, StderrConfig, Stderr> Unpin for Process<NameState, StdoutConfig, Stdout, StderrConfig, Stderr>
where NameState: Unpin, StdoutConfig: Unpin, StderrConfig: Unpin,

§

impl<NameState, StdoutConfig, Stdout, StderrConfig, Stderr> UnsafeUnpin for Process<NameState, StdoutConfig, Stdout, StderrConfig, Stderr>
where NameState: UnsafeUnpin, StdoutConfig: UnsafeUnpin, StderrConfig: UnsafeUnpin,

§

impl<NameState = Unnamed, StdoutConfig = Unset, Stdout = Unset, StderrConfig = Unset, Stderr = Unset> !UnwindSafe for Process<NameState, StdoutConfig, Stdout, StderrConfig, Stderr>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Sink for T
where T: Send + 'static,