Skip to main content

Io

Struct Io 

Source
pub struct Io<'a> {
    pub input: &'a mut (dyn BufRead + Send),
    pub out: &'a mut (dyn Write + Send),
    pub err: &'a mut (dyn Write + Send),
}
Expand description

The streams a verb uses (real stdio in Cli::run, buffers in tests). Send, so mcp can read and write on their own threads.

Fields§

§input: &'a mut (dyn BufRead + Send)§out: &'a mut (dyn Write + Send)§err: &'a mut (dyn Write + Send)

Implementations§

Source§

impl Io<'_>

Source

pub fn reply(&mut self, r: &Reply) -> Exit

Print a reply line and turn it into an exit code.

Source

pub fn fail(&mut self, json: bool, tool: &str, msg: impl Display) -> Exit

A failure: with json, the reply line on stdout (as Io::reply); without it, one line of plain text on stderr (<tool>: <message>), for a person reading a terminal.

Source

pub fn reply_as(&mut self, json: bool, tool: &str, r: &Reply) -> Exit

A reply: with json the line on stdout; without it a success is the result as indented JSON on stdout and an error is plain text on stderr (see Io::fail).

Source

pub fn usage(&mut self, msg: impl Display, usage: &str) -> Exit

A usage error: the reply line on stdout, a hint on stderr.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Io<'a>

§

impl<'a> !Sync for Io<'a>

§

impl<'a> !UnwindSafe for Io<'a>

§

impl<'a> Freeze for Io<'a>

§

impl<'a> Send for Io<'a>

§

impl<'a> Unpin for Io<'a>

§

impl<'a> UnsafeUnpin for Io<'a>

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

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.