Parser

Trait Parser 

Source
pub trait Parser {
    // Required method
    fn parse(&self, input: &str) -> Result<Table>;
}
Expand description

Trait for parsing table data from various input formats.

Implement this trait to add support for new table formats. All parsers should validate column consistency by using Table::new_validated.

§Examples

use table_extractor::{Parser, Table, error::Result};

struct CustomParser;

impl Parser for CustomParser {
    fn parse(&self, input: &str) -> Result<Table> {
        // Parse input into headers and rows
        let headers = vec!["col1".to_string(), "col2".to_string()];
        let rows = vec![vec!["val1".to_string(), "val2".to_string()]];

        // Use new_validated to ensure data integrity
        Table::new_validated(headers, rows)
    }
}

Required Methods§

Source

fn parse(&self, input: &str) -> Result<Table>

Parses the input string into a table.

§Errors

Returns an error if the input cannot be parsed or if the resulting table fails validation (inconsistent columns, too many columns, etc.).

Implementors§