Trait ffx_writer::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<(), Error>
       where Self::OutputItem: Display;

    // Provided methods
    fn has_schema() -> bool { ... }
    fn try_print_schema(&mut self) -> Result<(), Error> { ... }
    fn print(&mut self, value: impl Display) -> Result<(), Error> { ... }
    fn line(&mut self, value: impl Display) -> Result<(), Error> { ... }
}
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<(), Error>
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<(), Error>

source

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

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<(), Error>

Writes the value to standard output with a newline.

This is a no-op if is_machine returns true.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl ToolIO for SimpleWriter

source§

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

§

type OutputItem = T

source§

impl<T> ToolIO for VerifiedMachineWriter<T>
where T: Serialize + JsonSchema,

§

type OutputItem = T