tablefi

Crates.iotablefi
lib.rstablefi
version0.3.1
created_at2025-06-02 16:33:18.298418+00
updated_at2025-06-03 04:10:35.776403+00
descriptionSimple table to store, manipulate and format tabular data.
homepage
repositoryhttps://github.com/wyzzarz/tablefi
max_upload_size
id1698126
size90,461
Warner Zee (wyzzarz)

documentation

README

tablefi

Simple table to store, manipulate and format tabular data.

Documentation

https://docs.rs/tablefi

Usage

To bring this crate into your repository, either add tablefi to your Cargo.toml, or run cargo add tablefi.

Example

This example shows how to create a table, add columns and rows, perform arithmetic operations, and print the table as csv.

use rust_decimal::Decimal;
use tablefi::{Slice, Table};

fn main() {
    if let Err(e) = example() {
        eprintln!("Error: {}", e);
        std::process::exit(1);
    }   
}

fn example() -> Result<(), Box<dyn std::error::Error>> {
    // create a table from json
    let mut table: Table = Table::try_from(r#"[["a","b","c"],["1","2","3"]]"#).unwrap();

    // add a row
    table.push_row(Slice::from(vec!["4", "5", "6"]));

    // add total
    let row1 = table.row(1).ok_or_else(|| format!("Row at index {} not found", 1))?;
    let row2 = table.row(2).ok_or_else(|| format!("Row at index {} not found", 2))?;
    table.push_row(&row1 + &row2);

    // multiply value for a cell
    let cell = table.mut_cell(3, 2).ok_or_else(|| format!("Cell at row {} and column {} not found", 3, 2))?;
    cell.mul_value(Decimal::from(2));

    // output csv
    // a,b,c
    // 1,2,3
    // 4,5,6
    // 5,7,18
    let mut csv: Vec<u8> = Vec::new();
    table.write_csv(&mut csv)?;
    println!("{}", String::from_utf8(csv).unwrap());

    Ok(())
}

The above example can be run like so:

$ git clone https://github.com/wyzzarz/tablefi.git
$ cd tablefi
$ cargo run --example tablefi-example
Commit count: 27

cargo fmt