Skip to main content

LiveChild

Struct LiveChild 

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

A program a DetachedHandoff left running: its standard input is the application’s to write, its later output arrives as messages through DetachedHandoff::on_line.

Clones share the one program, so the application can keep one in its state and move others into background work. When the last clone is dropped — at the latest when the application’s state is dropped as the run ends — the program’s standard input is closed and it reads the end of its input; ending it before that is the application’s decision (LiveChild::close_stdin, LiveChild::kill).

After its first line the program runs in the background of the terminal, which the application draws on again. Its standard error is still the terminal, so it should keep quiet there from then on: anything it writes lands on the application’s screen until the next full redraw.

Implementations§

Source§

impl LiveChild

Source

pub fn for_tests() -> (Self, TestChild)

A stand-in for tests, with the handle a test drives it through: what the application writes is recorded there, and the test says the program’s lines and ends it. Answer a detached handoff with it through Harness::set_detached_outcome.

use qframe::runtime::{ChildLine, LiveChild};

let (child, program) = LiveChild::for_tests();
child.write_line("status")?;
assert_eq!(program.written(), ["status"]);
assert_eq!(child.try_wait()?, None, "it runs until the test ends it");
program.exit(Some(0));
assert_eq!(child.try_wait()?, Some(Some(0)));
Source

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

The program’s process id, or None for the stand-in of LiveChild::for_tests.

Source

pub fn write_line(&self, line: &str) -> Result<()>

Writes line and a newline to the program’s standard input. A line holding newlines reaches the program as several lines.

The write blocks while the pipe is full, which only happens when the program stops reading; a program that answers each line keeps it empty.

§Errors

Returns an error once the standard input is closed (io::ErrorKind::BrokenPipe) or the program no longer reads it.

Source

pub fn close_stdin(&self)

Closes the program’s standard input, for every clone: the program reads the end of its input, which is how a helper that serves one line at a time is asked to finish. Closing it again does nothing.

Source

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

Ends the program at once (SIGKILL on Unix); its ChildLine::Ended follows. Killing one that already ended does nothing.

§Errors

Returns the system’s error, such as when the program runs as another user and may not be signalled, which is the case for one started through pkexec or sudo: close its standard input instead.

Source

pub fn try_wait(&self) -> Result<Option<Option<i32>>>

How the program ended, without waiting: None while it runs, then Some(code), where code is None when a signal ended it, as in HandoffOutcome::Finished.

§Errors

Returns the system’s error when the program’s state cannot be read.

Trait Implementations§

Source§

impl Clone for LiveChild

Source§

fn clone(&self) -> LiveChild

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LiveChild

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for LiveChild

Source§

impl PartialEq for LiveChild

Two handles are equal when they are clones of each other: the same program.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.