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§
Sourcetype OutputItem
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§
Sourcefn is_machine_supported() -> bool
fn is_machine_supported() -> bool
Whether this can theoretically support machine output given the right configuration.
Sourcefn is_machine(&self) -> bool
fn is_machine(&self) -> bool
Returns true if the receiver was configured to output for machines.
Sourcefn stderr(&mut self) -> &mut Box<dyn Write>
fn stderr(&mut self) -> &mut Box<dyn Write>
Returns an error stream that errors can be written to.
Sourcefn item(&mut self, value: &Self::OutputItem) -> Result<()>where
Self::OutputItem: Display,
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§
Sourcefn has_schema() -> bool
fn has_schema() -> bool
Is a schema of the output type available.
fn try_print_schema(&mut self) -> Result<()>
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.