pub struct ScriptProcess { /* private fields */ }Expand description
Manages a single script subprocess with JSON-line communication.
The subprocess receives ScriptEvent objects serialized as JSON lines on stdin,
and emits ScriptCommand objects as JSON lines on stdout. Stderr is captured
separately for error reporting.
Implementations§
Source§impl ScriptProcess
impl ScriptProcess
Sourcepub fn spawn(
command: &str,
args: &[&str],
env_vars: &HashMap<String, String>,
) -> Result<ScriptProcess, String>
pub fn spawn( command: &str, args: &[&str], env_vars: &HashMap<String, String>, ) -> Result<ScriptProcess, String>
Spawn a script subprocess with piped stdin/stdout/stderr.
Starts background threads to read stdout (parsing JSON into ScriptCommand)
and stderr (collecting error lines).
§Arguments
command- The command to execute (e.g., “python3”).args- Arguments to pass to the command.env_vars- Additional environment variables to set for the subprocess.
§Errors
Returns an error string if the subprocess cannot be spawned.
Sourcepub fn is_running(&mut self) -> bool
pub fn is_running(&mut self) -> bool
Check if the child process is still alive.
Uses try_wait() to check without blocking. Returns false if the process
has exited or if there is no child process.
Sourcepub fn send_event(&mut self, event: &ScriptEvent) -> Result<(), String>
pub fn send_event(&mut self, event: &ScriptEvent) -> Result<(), String>
Serialize a ScriptEvent to JSON and write it to the child’s stdin as a line.
§Errors
Returns an error if the stdin writer is not available or if the write fails.
Sourcepub fn read_commands(&self) -> Vec<ScriptCommand>
pub fn read_commands(&self) -> Vec<ScriptCommand>
Drain pending commands from the command buffer.
Returns all commands that have been parsed from the child’s stdout since the last call to this method.
Sourcepub fn read_errors(&self) -> Vec<String>
pub fn read_errors(&self) -> Vec<String>
Drain pending error lines from the error buffer.
Returns all lines that have been read from the child’s stderr since the last call to this method.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ScriptProcess
impl !RefUnwindSafe for ScriptProcess
impl Send for ScriptProcess
impl Sync for ScriptProcess
impl Unpin for ScriptProcess
impl UnsafeUnpin for ScriptProcess
impl !UnwindSafe for ScriptProcess
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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