Skip to main content

CommandSpec

Struct CommandSpec 

Source
pub struct CommandSpec { /* private fields */ }
Expand description

An argv-based candidate command with bounded execution policy.

Implementations§

Source§

impl CommandSpec

Source

pub fn new(program: impl Into<PathBuf>) -> Self

Creates a command that never invokes a shell.

Source

pub fn arg(self, argument: impl Into<String>) -> Self

Appends one literal argv argument.

Source

pub fn args<I, S>(self, arguments: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Appends literal argv arguments.

Source

pub fn current_dir(self, path: impl Into<PathBuf>) -> Self

Sets the controlled child working directory.

Source

pub fn timeout(self, timeout: Duration) -> Self

Sets the maximum wall-clock execution time.

The value is an unconditional maximum bound on the whole bounded execution: it is evaluated whether or not the direct child has already exited, so run_bounded always returns. The deadline starts once the spawn has returned, so a blocking spawn is not covered by it.

run_bounded states the exact bound, the teardown allowance, and what a caller observes.

Source

pub fn max_output_bytes(self, limit: usize) -> Self

Sets the per-stream output bound.

The bound applies to each stream separately: stdout and stderr are captured independently, so one run may capture up to twice the configured value in total. A stream that exceeds the bound is reported through CommandOutput::output_limited and its captured bytes are discarded, so that stream is reported as empty.

Source

pub fn environment( self, name: impl Into<String>, value: impl Into<String>, ) -> Self

Adds one explicit environment variable; inherited environment is cleared.

Source

pub fn stdin_data(self, data: impl Into<Vec<u8>>) -> Self

Attaches a bounded stdin payload for the command to read.

The builder is infallible: the bound is enforced at execution time, not here, so an oversized payload is rejected by run_bounded before any child is spawned rather than by this builder.

Without a payload the child’s stdin is null, exactly as before. With a payload the child’s stdin is a pipe, and a dedicated writer thread writes the bytes and closes the pipe, so the command observes EOF when the payload has been delivered. The writer is bounded by the same deadline that bounds the output readers.

The payload is bounded by MAX_STDIN_BYTES, inclusively.

Trait Implementations§

Source§

impl Clone for CommandSpec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CommandSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.