Skip to main content

DrainState

Struct DrainState 

Source
pub struct DrainState<F>
where F: FnMut(&[u8]) -> bool,
{ /* private fields */ }
Expand description

Orchestrates non-blocking process I/O.

DrainState tracks the state of stdin, stdout, and stderr pipes for a single process. It handles the multiplexing of data between these pipes and internal buffers.

§Example

while !drain.is_done() {
    let mut events = Vec::new();
    reactor.wait(&mut events, 64, -1)?;
    for ev in events {
        // Map event tokens to drain calls...
    }
}

Implementations§

Source§

impl<F> DrainState<F>
where F: FnMut(&[u8]) -> bool,

Source

pub fn new( stdin_fd: Option<Fd>, stdin_buf: Option<Box<[u8]>>, stdout_fd: Option<Fd>, stderr_fd: Option<Fd>, limit: usize, early_exit: Option<F>, ) -> Result<Self, CoreError>

Initialize a new drain state for the provided descriptors.

This consumes the descriptors and sets them to non-blocking mode.

Source

pub fn is_done(&self) -> bool

Returns true if all pipes have been closed or fully drained.

Source

pub fn write_stdin(&mut self) -> Result<bool, CoreError>

Perform a non-blocking write to stdin if pending.

Source

pub fn read_fd(&mut self, is_stdout: bool) -> Result<bool, CoreError>

Perform a non-blocking read from stdout or stderr.

Source

pub fn into_parts(self) -> (Vec<u8>, Vec<u8>)

Consume the state and return (stdout, stderr) buffers.

Source

pub fn output_limit_exceeded(&self) -> bool

Return whether the combined stdout+stderr output limit was exceeded.

Source

pub fn stdout_early_exited(&self) -> bool

Return whether stdout was explicitly stopped by the early-exit predicate.

Auto Trait Implementations§

§

impl<F> Freeze for DrainState<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for DrainState<F>
where F: RefUnwindSafe,

§

impl<F> Send for DrainState<F>
where F: Send,

§

impl<F> Sync for DrainState<F>
where F: Sync,

§

impl<F> Unpin for DrainState<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for DrainState<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for DrainState<F>
where F: UnwindSafe,

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.