Skip to main content

P4Command

Struct P4Command 

Source
pub struct P4Command<'a> { /* private fields */ }
Expand description

Builder-style interface for running a single p4 command.

Obtain one via P4Cli::command() and chain configuration calls before calling run.

Implementations§

Source§

impl<'a> P4Command<'a>

Source

pub fn arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self

Append a single argument.

Source

pub fn args(&mut self, args: &[impl AsRef<OsStr>]) -> &mut Self

Append all arguments from a slice.

Source

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

Maximum wall-clock time the process is allowed to run. When exceeded the process is killed.

Note: Only the direct child process is terminated, not its descendants (no process-tree kill).

Source

pub fn cwd(&mut self, path: impl Into<PathBuf>) -> &mut Self

Working directory for the child process.

Source

pub fn env( &mut self, key: impl Into<OsString>, val: impl Into<OsString>, ) -> &mut Self

Set an environment variable for the child process.

Source

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

Provide data to be piped to the child’s stdin.

Source

pub fn run(&mut self) -> Result<P4Output>

Execute the command and collect output.

Stdout and stderr are read concurrently in separate OS threads to prevent pipe-full deadlocks. If a timeout was set, the process is killed once the deadline is reached.

Source

pub fn stream(&mut self) -> Result<P4Stream>

Run the command and return a streaming iterator over output lines.

Stdout and stderr are read concurrently by two OS threads and merged into a single stream. The final event is always P4StreamEvent::Exit with the exit code (unless the stream is dropped early).

Unlike run, this method does not support timeout — the caller controls iteration and can drop the stream to cancel.

Auto Trait Implementations§

§

impl<'a> Freeze for P4Command<'a>

§

impl<'a> RefUnwindSafe for P4Command<'a>

§

impl<'a> Send for P4Command<'a>

§

impl<'a> Sync for P4Command<'a>

§

impl<'a> Unpin for P4Command<'a>

§

impl<'a> UnsafeUnpin for P4Command<'a>

§

impl<'a> UnwindSafe for P4Command<'a>

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, 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.