#table #print #terminal #format #pretty-table #macro-derive #pretty-print

no-std tabled

An easy to use library for pretty print tables of Rust structs and enums

33 unstable releases

new 0.17.0 Nov 22, 2024
0.15.0 Dec 20, 2023
0.14.0 Aug 4, 2023
0.13.0 Jul 24, 2023
0.1.0 Mar 23, 2020

#1 in Visualization

Download history 70220/week @ 2024-08-04 77860/week @ 2024-08-11 77096/week @ 2024-08-18 95131/week @ 2024-08-25 83145/week @ 2024-09-01 86074/week @ 2024-09-08 77083/week @ 2024-09-15 93666/week @ 2024-09-22 113065/week @ 2024-09-29 92223/week @ 2024-10-06 111876/week @ 2024-10-13 99013/week @ 2024-10-20 106753/week @ 2024-10-27 80840/week @ 2024-11-03 126719/week @ 2024-11-10 134745/week @ 2024-11-17

453,298 downloads per month
Used in 362 crates (278 directly)

MIT license

1MB
23K SLoC

github crates.io docs.rs build status coverage dependency status

tabled

An easy to use library for pretty printing tables of Rust structs and enums.

There are more examples and you can find in this README.

Usage

To print a list of structs or enums as a table your types should implement the the Tabled trait or derive it with a #[derive(Tabled)] macro. Most of the default types implement the trait out of the box.

Most of a table configuration can be found in tabled::settings module.

use tabled::{Table, Tabled};
use testing_table::assert_table;

#[derive(Tabled)]
struct Language<'a> {
    name: &'a str,
    designed_by: &'a str,
    invented_year: usize,
}

let languages = vec![
    Language { name: "C",    designed_by: "Dennis Ritchie", invented_year: 1972 },
    Language { name: "Go",   designed_by: "Rob Pike",       invented_year: 2009 },
    Language { name: "Rust", designed_by: "Graydon Hoare",  invented_year: 2010 },
    Language { name: "Hare", designed_by: "Drew DeVault",   invented_year: 2022 },
];

let table = Table::new(languages);

assert_table!(
    table,
    "+------+----------------+---------------+"
    "| name | designed_by    | invented_year |"
    "+------+----------------+---------------+"
    "| C    | Dennis Ritchie | 1972          |"
    "+------+----------------+---------------+"
    "| Go   | Rob Pike       | 2009          |"
    "+------+----------------+---------------+"
    "| Rust | Graydon Hoare  | 2010          |"
    "+------+----------------+---------------+"
    "| Hare | Drew DeVault   | 2022          |"
    "+------+----------------+---------------+"
);

The same example but we are building a table step by step.

use tabled::{builder::Builder, settings::Style};
use testing_table::assert_table;

let mut builder = Builder::new();
builder.push_record(["C", "Dennis Ritchie", "1972"]);
builder.push_record(["Go", "Rob Pike", "2009"]);
builder.push_record(["Rust", "Graydon Hoare", "2010"]);
builder.push_record(["Hare", "Drew DeVault", "2022"]);

let mut table = builder.build();
table.with(Style::ascii_rounded());

assert_table!(
    table,
    ".------------------------------."
    "| C    | Dennis Ritchie | 1972 |"
    "| Go   | Rob Pike       | 2009 |"
    "| Rust | Graydon Hoare  | 2010 |"
    "| Hare | Drew DeVault   | 2022 |"
    "'------------------------------'"
);

Dependencies

~2MB
~33K SLoC