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
impl LiveChild
Sourcepub fn for_tests() -> (Self, TestChild)
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)));Sourcepub fn id(&self) -> Option<u32>
pub fn id(&self) -> Option<u32>
The program’s process id, or None for the stand-in of LiveChild::for_tests.
Sourcepub fn write_line(&self, line: &str) -> Result<()>
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.
Sourcepub fn close_stdin(&self)
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.
Sourcepub fn kill(&self) -> Result<()>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LiveChild
impl RefUnwindSafe for LiveChild
impl Send for LiveChild
impl Sync for LiveChild
impl Unpin for LiveChild
impl UnsafeUnpin for LiveChild
impl UnwindSafe for LiveChild
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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