Skip to main content

NativeProcess

Struct NativeProcess 

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

A cross-platform child process with optional output capture.

NativeProcess wraps std::process::Command with the crate’s process-tree containment, capture draining, timeout, and terminal-control behavior. Methods are synchronous and are safe to call from ordinary blocking code.

Implementations§

Source§

impl NativeProcess

Source

pub fn new(config: ProcessConfig) -> Self

Create a process wrapper from a ProcessConfig.

The child is not spawned until Self::start is called. Process observation is off by default: no lifecycle events are emitted unless Self::with_observer is used instead.

Source

pub fn with_observer( config: ProcessConfig, observer: ObserverConfig, ) -> (Self, ObserverSubscriber)

Create a process wrapper with process observation enabled (Phase 1 of #221).

Returns the wrapper paired with an ObserverSubscriber that receives a started event when Self::start spawns the child and exactly one exited event when the child is reaped — for the categories the config requests that are actually Supported (only Lifecycle in Phase 1; see ObserverCapabilities::negotiate).

The emitter never blocks on a slow or dropped subscriber.

Source

pub fn start(&self) -> Result<(), ProcessError>

Spawn the configured child process.

Returns ProcessError::AlreadyStarted if the same wrapper already owns a running child.

Source

pub fn write_stdin(&self, data: &[u8]) -> Result<(), ProcessError>

Write bytes to the child’s stdin and then close stdin.

Source

pub fn write_stdin_streaming(&self, data: &[u8]) -> Result<(), ProcessError>

Write to the child’s stdin without closing it afterwards, so the caller can issue additional writes. Used by interactive pipe-backed sessions (#130 milestone 3) where the daemon keeps stdin open across multiple client input frames.

Source

pub fn close_stdin(&self) -> Result<(), ProcessError>

Explicitly close the child’s stdin (signals EOF to the child). Idempotent: returns Ok if stdin was already closed.

Source

pub fn poll(&self) -> Result<Option<i32>, ProcessError>

Check whether the child has exited without blocking.

Returns Ok(None) while the process is still running.

Source

pub fn wait(&self, timeout: Option<Duration>) -> Result<i32, ProcessError>

Wait for the child to exit.

When timeout is Some, returns ProcessError::Timeout if the child does not exit before the duration elapses.

Source

pub fn kill(&self) -> Result<(), ProcessError>

Forcefully terminate the child process.

Source

pub fn terminate(&self) -> Result<(), ProcessError>

Terminate the child process.

This currently uses the same hard-kill path as Self::kill.

Source

pub fn terminate_group_soft(&self) -> Result<(), ProcessError>

Send the OS-appropriate soft termination signal to the child’s process group (POSIX: SIGTERM to -pid; Windows: no soft path implemented yet — returns Ok without doing anything so callers can run the same code on both platforms and rely on the post- grace hard kill).

Requires ProcessConfig.create_process_group=true on POSIX so that -pid resolves to the child’s own group. With the default create_process_group=false, the kill would walk back to the caller’s group; the method silently no-ops in that case to avoid signaling the wrong tree.

Used by the daemon-side pipe sessions (#130 M4 follow-up) so that TerminationOutcome::SoftExit becomes meaningful on POSIX.

Source

pub fn close(&self) -> Result<(), ProcessError>

Close the process wrapper by terminating the child when it is running.

Source

pub fn pid(&self) -> Option<u32>

Return the child process id when the wrapper currently owns a child.

Source

pub fn returncode(&self) -> Option<i32>

Return the cached exit code when the child has exited.

Source

pub fn has_pending_stream(&self, stream: StreamKind) -> bool

Return whether captured output is queued for one stream.

Source

pub fn has_pending_combined(&self) -> bool

Return whether captured combined output is queued.

Source

pub fn drain_stream(&self, stream: StreamKind) -> Vec<Vec<u8>>

Drain and return all queued output for one stream.

Source

pub fn drain_combined(&self) -> Vec<StreamEvent>

Drain and return all queued combined output events.

Source

pub fn read_stream( &self, stream: StreamKind, timeout: Option<Duration>, ) -> ReadStatus<Vec<u8>>

Read the next captured chunk from one stream.

Returns ReadStatus::Timeout when timeout elapses before output or EOF is observed.

Source

pub fn read_combined( &self, timeout: Option<Duration>, ) -> ReadStatus<StreamEvent>

Read the next captured combined stream event.

Source

pub fn captured_stdout(&self) -> Vec<Vec<u8>>

Return the retained stdout history.

Source

pub fn captured_stderr(&self) -> Vec<Vec<u8>>

Return the retained stderr history.

Source

pub fn captured_combined(&self) -> Vec<StreamEvent>

Return the retained combined stdout/stderr event history.

Source

pub fn captured_stream_bytes(&self, stream: StreamKind) -> usize

Return the retained byte count for one captured stream.

Source

pub fn captured_combined_bytes(&self) -> usize

Return the retained byte count for combined captured output.

Source

pub fn clear_captured_stream(&self, stream: StreamKind) -> usize

Clear retained output history for one stream and return freed bytes.

Source

pub fn clear_captured_combined(&self) -> usize

Clear retained combined output history and return freed bytes.

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.