Trait ToolIO

Source
pub trait ToolIO: Write + Sized {
    type OutputItem;

    // Required methods
    fn is_machine_supported() -> bool;
    fn is_machine(&self) -> bool;
    fn stderr(&mut self) -> &mut Box<dyn Write>;
    fn item(&mut self, value: &Self::OutputItem) -> Result<()>
       where Self::OutputItem: Display;

    // Provided methods
    fn has_schema() -> bool { ... }
    fn try_print_schema(&mut self) -> Result<()> { ... }
    fn print(&mut self, value: impl Display) -> Result<()> { ... }
    fn line(&mut self, value: impl Display) -> Result<()> { ... }
}
Expand description

ToolIO defines the necessary functions to perform output from a tool, potentially including type-safe machine output if required.

There are three provided implementations: and [crate::SimpleWriter]. These provide either type-safe, type-safe with schema, or string-only output respectively.

Required Associated Types§

Source

type OutputItem

The type of object that is expected for the Self::item call (or any machine output writing functions that may be added by an implementation)

Required Methods§

Source

fn is_machine_supported() -> bool

Whether this can theoretically support machine output given the right configuration.

Source

fn is_machine(&self) -> bool

Returns true if the receiver was configured to output for machines.

Source

fn stderr(&mut self) -> &mut Box<dyn Write>

Returns an error stream that errors can be written to.

Source

fn item(&mut self, value: &Self::OutputItem) -> Result<()>
where Self::OutputItem: Display,

Displays the item in whatever formatted style is most appropriate based on is_machine and the underlying implementation

Provided Methods§

Source

fn has_schema() -> bool

Is a schema of the output type available.

Source

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

Source

fn print(&mut self, value: impl Display) -> Result<()>

Writes the value to standard output without a newline.

This is a no-op if is_machine returns true.

Source

fn line(&mut self, value: impl Display) -> Result<()>

Writes the value to standard output with a newline.

This is a no-op if is_machine returns true.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> ToolIO for JsonWriter<T>
where T: Serialize,