An easy to use library for pretty printing tables of Rust struct
s and enum
s.
There are more examples and you can find in this README
.
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.
```rust use tabled::{Table, Tabled};
struct Language { name: String, designedby: String, inventedyear: usize, }
impl Language { fn new(name: &str, designedby: &str, inventedyear: usize) -> Self { Self { name: name.tostring(), designedby: designedby.tostring(), 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 | designedby | inventedyear |\n\ +------+----------------+---------------+\n\ | C | Dennis Ritchie | 1972 |\n\ +------+----------------+---------------+\n\ | Go | Rob Pike | 2009 |\n\ +------+----------------+---------------+\n\ | Rust | Graydon Hoare | 2010 |\n\ +------+----------------+---------------+";
assert_eq!(table, expected); ```