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
84,885 downloads per month
Used in 115 crates
(99 directly)
565KB
12K
SLoC
tabled
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
.
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