This library provides an interface to pretty print vectors of structs
The common and probably the best way to begin is to annotate your type with
#[derive(Tabled)]
. You can also implement it on your own as well.
There's an example. Precisely it can be printed and you
will see the content of expected
variable as an output.
```rust use tabled::{Tabled, table};
struct Language { name: String, designedby: String, inventedyear: usize, }
let languages = vec![ Language{ name: "C".toowned(), designedby: "Dennis Ritchie".toowned(), inventedyear: 1972 }, Language{ name: "Rust".toowned(), designedby: "Graydon Hoare".toowned(), inventedyear: 2010}, ];
let table = table(&languages); let expected = "+------+----------------+---------------+\n\ | name | designedby | inventedyear |\n\ +------+----------------+---------------+\n\ | C | Dennis Ritchie | 1972 |\n\ +------+----------------+---------------+\n\ | Rust | Graydon Hoare | 2010 |\n\ +------+----------------+---------------+\n";
assert_eq!(expected, table); ```
It should have a clue in what why print the field
accordingly each field should implement std::fmt::Display
The example below is not compiled
```rust,compile_fail
struct SomeType { field1: SomeOtherType, }
struct SomeOtherType; ``` This crate implement the trait for default types. Therefore you can use this to print one column vectors
```rust use tabled::{Tabled, table};
let somenumbers = [1, 2, 3]; let table = table(&somenumbers); ```
License: Apache-2.0