Writer

Trait Writer 

Source
pub trait Writer {
    // Required method
    fn write(&self, table: &Table, output: &mut dyn Write) -> Result<()>;
}
Expand description

Trait for writing table data to various output formats.

Implement this trait to add support for new output formats.

§Examples

use table_extractor::{Writer, Table, error::Result};
use std::io::Write as IoWrite;

struct CustomWriter;

impl Writer for CustomWriter {
    fn write(&self, table: &Table, output: &mut dyn IoWrite) -> Result<()> {
        // Write headers
        writeln!(output, "{}", table.headers().join(","))?;

        // Write rows
        for row in table.rows() {
            writeln!(output, "{}", row.join(","))?;
        }

        Ok(())
    }
}

Required Methods§

Source

fn write(&self, table: &Table, output: &mut dyn Write) -> Result<()>

Writes the table to the provided output stream.

§Errors

Returns an error if writing fails or if the table data is invalid for the output format (e.g., delimiter conflicts).

Implementors§