#table #print #pretty-table #format #terminal

tabled

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

21 releases (9 breaking)

0.10.0 Oct 18, 2022
0.9.0-fix.docs.rs.4 Oct 6, 2022
0.8.0 Jul 22, 2022
0.5.0 Feb 10, 2022
0.1.0 Mar 23, 2020

#16 in Text processing

Download history 14926/week @ 2022-11-29 13007/week @ 2022-12-06 12760/week @ 2022-12-13 10654/week @ 2022-12-20 8826/week @ 2022-12-27 13987/week @ 2023-01-03 16821/week @ 2023-01-10 16302/week @ 2023-01-17 15947/week @ 2023-01-24 19286/week @ 2023-01-31 22971/week @ 2023-02-07 24917/week @ 2023-02-14 23089/week @ 2023-02-21 21378/week @ 2023-02-28 20997/week @ 2023-03-07 16794/week @ 2023-03-14

84,885 downloads per month
Used in 115 crates (99 directly)

MIT license

565KB
12K 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.

use tabled::{Table, Tabled};

#[derive(Tabled)]
struct Language {
    name: String,
    designed_by: String,
    invented_year: usize,
}

impl Language {
    fn new(name: &str, designed_by: &str, invented_year: usize) -> Self {
        Self {
            name: name.to_string(),
            designed_by: designed_by.to_string(),
            invented_year,
        }
    }
}

let languages = vec![
    Language::new("C", "Dennis Ritchie", 1972),
    Language::new("Go", "Rob Pike", 2009),
    Language::new("Rust", "Graydon Hoare", 2010),
];

let table = Table::new(languages).to_string();

let expected = "+------+----------------+---------------+\n\
                | name | designed_by    | invented_year |\n\
                +------+----------------+---------------+\n\
                | C    | Dennis Ritchie | 1972          |\n\
                +------+----------------+---------------+\n\
                | Go   | Rob Pike       | 2009          |\n\
                +------+----------------+---------------+\n\
                | Rust | Graydon Hoare  | 2010          |\n\
                +------+----------------+---------------+";

assert_eq!(table, expected);

Dependencies

~87–450KB