Skip to main content

NativeOutputCapture

Struct NativeOutputCapture 

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

An owned reader of a native child stdout/stderr pipe, with bounded byte retention.

Unix read ends use nonblocking I/O; Windows read ends use owned overlapped I/O. Cancellation wakes the private reader; no user callbacks run on it. cancel, finish_within and Drop all join the reader and close its pipe, even when a descendant keeps the write end open. Idle readers check the pipe every 20 ms; cancellation also wakes that wait immediately.

This guarantee cannot be provided for arbitrary Read; use crate::OutputCapture only when the reader’s lifetime is controlled separately. Do not change the native read end’s blocking mode through another handle while this capture owns it. Windows requires a byte pipe opened for overlapped I/O (including OwnedCommand pipes); disconnected overlapped pipes are accepted as EOF without issuing a read. Construction rejects unsupported handles before starting a reader.

Implementations§

Source§

impl NativeOutputCapture

Source

pub fn stdout(pipe: ChildStdout, max_bytes: usize) -> Result<Self>

Own & drain a child’s stdout. Errors before spawning a reader if the pipe cannot support cancellable native I/O or the operating system cannot start the reader thread.

Source

pub fn stderr(pipe: ChildStderr, max_bytes: usize) -> Result<Self>

Own & drain a child’s stderr, with the same guarantees as stdout.

Source

pub fn snapshot(&self) -> CapturedOutput

What has been captured so far. This does not stop the reader.

Source

pub fn is_complete(&self) -> bool

True only if the pipe reached EOF. A deadline/cancellation can return partial bytes without exceeding the retention cap; CapturedOutput::truncated describes cap loss.

Source

pub fn take_error(&self) -> Option<Error>

Take the native read error, if any. Cancellation is not an error.

Source

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

Wait up to timeout for EOF/error, then cancel & join the reader. Always closes the read end before returning; a writer retained by a descendant cannot extend the wait. Returned bytes may be partial: consult is_complete.

Source

pub fn cancel(&mut self) -> CapturedOutput

Cancel immediately, join the reader & return retained bytes. Idempotent.

Trait Implementations§

Source§

impl Drop for NativeOutputCapture

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> 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 = !

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.