HeadlessIo

Struct HeadlessIo 

Source
pub struct HeadlessIo {
    pub output: Vec<String>,
    /* private fields */
}
Expand description

A NarjuIo that reads from a pre-set script and writes to a buffer.

read_line pops the next scripted line, then reports EOF forever; print appends to output (and, if constructed via new_shared, to a shared sink readable after the box has been consumed).

Fields§

§output: Vec<String>

Everything printed so far, one entry per print call.

Implementations§

Source§

impl HeadlessIo

Source

pub fn new(input: Vec<String>) -> Self

Construct with the given input script and an empty output buffer.

Source

pub fn empty() -> Self

Construct with no input at all: read_line reports EOF immediately. Sufficient for code that never calls read.

Source

pub fn new_shared(input: Vec<String>) -> (Self, Rc<RefCell<Vec<String>>>)

Like new, but also returns a shared handle to the print output, so callers can read what a session printed after the Box<dyn NarjuIo> has been consumed by TopLevel/EvalCtx.

Source

pub fn drain_output(&mut self) -> Vec<String>

Take everything printed so far, leaving the buffer empty.

Trait Implementations§

Source§

impl NarjuIo for HeadlessIo

Source§

fn read_line(&mut self, _prompt: &str) -> Result<Option<String>, NarjuError>

Read one line of input, displaying prompt where that makes sense. Returns Ok(None) at end of input (EOF, Ctrl-D, or an exhausted script), which the floor’s read maps to nil.
Source§

fn print(&mut self, s: &str) -> Result<(), NarjuError>

Write one line of output (no trailing newline in s; the implementation supplies it).

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