Skip to main content

Formatter

Trait Formatter 

Source
pub trait Formatter: Send + Sync {
    // Required methods
    fn write_header(
        &mut self,
        writer: &mut dyn Write,
        columns: &[Column],
    ) -> Result<()>;
    fn write_row(&mut self, writer: &mut dyn Write, row: &Row) -> Result<()>;
    fn write_footer(&mut self, writer: &mut dyn Write) -> Result<()>;
    fn supports_streaming(&self) -> bool;
}
Expand description

Trait for output formatters.

All formatters must be Send + Sync to allow use in multi-threaded contexts.

Required Methods§

Source

fn write_header( &mut self, writer: &mut dyn Write, columns: &[Column], ) -> Result<()>

Write the header (column names) to the output.

For streaming formats (json, jsonl, csv, tsv), this is called immediately. For buffered formats (table), this is called after buffer evaluation.

Source

fn write_row(&mut self, writer: &mut dyn Write, row: &Row) -> Result<()>

Write a single row to the output.

Write the footer to the output.

For json format, this closes the array. For others, this may be a no-op.

Source

fn supports_streaming(&self) -> bool

Returns true if this formatter supports streaming output.

Streaming formats (json, jsonl, csv, tsv) write rows immediately. Non-streaming formats (table) buffer rows before output.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§