Skip to main content

ReplayHost

Struct ReplayHost 

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

A host that plays bytes back instead of running anything: for tests, demos and recordings. What it plays is given up front (output, exit) or later through a ReplayHandle, which also sees what the pane sent it.

use rich_embed::{ExitStatus, ReplayHost};

let host = ReplayHost::new().output("hello\r\n").exit(ExitStatus::with_code(0));
let handle = host.handle();
assert!(handle.written().is_empty());

Implementations§

Source§

impl ReplayHost

Source

pub fn new() -> ReplayHost

Source

pub fn output(self, bytes: impl AsRef<[u8]>) -> ReplayHost

Play bytes as the program’s output once it starts.

Source

pub fn exit(self, status: ExitStatus) -> ReplayHost

Exit with status once the output has played.

Source

pub fn handle(&self) -> ReplayHandle

A handle to feed more output, end the program, and see what was sent to it. It may go to another thread.

Trait Implementations§

Source§

impl Default for ReplayHost

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PtyHost for ReplayHost

Source§

fn start(&mut self, columns: u16, rows: u16) -> Result<()>

Start the program on a screen columns x rows cells. Called once, when the pane is first laid out.
Source§

fn write(&mut self, bytes: &[u8]) -> Result<()>

Send bytes to the program, as if typed. A host may refuse with io::ErrorKind::WouldBlock while the program’s input is full (it is not reading it): nothing was sent, and the same bytes can be sent again later.
Source§

fn resize(&mut self, columns: u16, rows: u16) -> Result<()>

The pane is now columns x rows cells.
Source§

fn read(&mut self) -> Vec<u8> ⓘ

The output that arrived since the last call; empty when there is none. Never blocks.
Source§

fn set_notify(&mut self, notify: Notify)

Call notify whenever output arrives or the program exits. Given once, before or after start; a host with something already waiting calls it at once.
Source§

fn exit_status(&mut self) -> Option<ExitStatus>

How the program ended, once it has, and once the output it wrote before that has been read.
Source§

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

End the program. Also called when the pane goes away.

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, 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.