summaryrefslogtreecommitdiffstats
path: root/vendor/tabled/examples/table.rs
blob: d6d5c392cd2a85796e283f37aaa02dc5700b5aae (plain)
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
//! This example demonstrates the fundemental qualities of the [crate](https://crates.io/crates/tabled) [`tabled`].
//!
//! * [`tabled`] is powered by convenient [procedural macros](https://doc.rust-lang.org/reference/procedural-macros.html#procedural-macros)
//! like [`Tabled`]; a deriveable trait that allows your custom
//! structs and enums to be represented with [`tabled`]'s powerful suite of features.
//!
//! * [`Table`] is the root object to which all of [`tabled`]'s implementation
//! tools guide you, and from which all of its customization options derive value.
//! The READMEs, examples, and docs found in this project will show you many dozens
//! of ways you can build tables, and show you how to use the available tools
//! to build the data representations that best fit your needs.
//!
//! * [`Table::with()`] plays a central role in giving the user control over their
//! displays. A majority of [`Table`] customizations are implemented through this highly
//! dynamic function. A few [`TableOptions`](TableOption) include:
//!     * [`Style`]
//!     * [`Modify`]
//!     * [`Alignment`]
//!     * [`Padding`]

use tabled::{
    settings::{object::Rows, Alignment, Modify, Style},
    Table, Tabled,
};

#[derive(Debug, Tabled)]
struct Distribution {
    name: String,
    based_on: String,
    is_active: bool,
}

impl Distribution {
    fn new(name: &str, base: &str, is_active: bool) -> Self {
        Self {
            based_on: base.to_owned(),
            name: name.to_owned(),
            is_active,
        }
    }
}

fn main() {
    let data = [
        Distribution::new("Debian", "", true),
        Distribution::new("Arch", "", true),
        Distribution::new("Manjaro", "Arch", true),
    ];

    let mut table = Table::new(data);
    table
        .with(Style::markdown())
        .with(Modify::new(Rows::first()).with(Alignment::center()));

    println!("{table}");
}