Trait ffx_writer::ToolIO

source ·
pub trait ToolIO: Write + Sized {
    type OutputItem;

    const OUTPUT_SCHEMA: Option<StaticType> = None;

    // 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 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 two provided implementations, crate::MachineWriter and crate::SimpleWriter, which provide either type-safe 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)

Provided Associated Constants§

source

const OUTPUT_SCHEMA: Option<StaticType> = None

The schema the output item is expected to follow.

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 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§