1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
//! This example demonstrates using the [`col!`] and [`row!`] macros to easily
//! organize multiple tables together into a single, new [`Table`] display.
//!
//! * 🚩 This example requires the `macros` feature.
//!
//! * Note how both macros can be used in combination to layer
//! several table arrangements together.
//!
//! * Note how [`col!`] and [`row!`] support idiomatic argument duplication
//! with the familiar `[T; N]` syntax.
use tabled::{
col, row,
settings::{Alignment, Style},
Table, Tabled,
};
#[derive(Tabled)]
struct Person {
name: String,
age: u8,
is_validated: bool,
}
impl Person {
fn new(name: &str, age: u8, is_validated: bool) -> Self {
Self {
name: name.into(),
age,
is_validated,
}
}
}
fn main() {
let validated = [Person::new("Sam", 31, true), Person::new("Sarah", 26, true)];
let not_validated = [
Person::new("Jack Black", 51, false),
Person::new("Michelle Goldstein", 44, true),
];
let unsure = [
Person::new("Jon Doe", 255, false),
Person::new("Mark Nelson", 13, true),
Person::new("Terminal Monitor", 0, false),
Person::new("Adam Blend", 17, true),
];
let table_validated = Table::new(validated).with(Style::ascii()).to_string();
let table_not_validated = Table::new(not_validated).with(Style::modern()).to_string();
let table_unsure = Table::new(unsure).with(Style::ascii_rounded()).to_string();
let output1 = row![table_validated, table_not_validated];
let output2 = col![table_unsure; 3];
let output3 = col![
row![table_validated, table_not_validated].with(Style::empty()),
table_unsure
]
.with(Alignment::center())
.to_string();
println!("{output1}");
println!("{output2}");
println!("{output3}");
}
|