File: column_names.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (45 lines) | stat: -rw-r--r-- 1,309 bytes parent folder | download | duplicates (16)
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
//! This example demonstrates how to set column names on a top horizontal line.
//!
//! It sets a `clickhouse` like table style (first seen on).

use tabled::{
    settings::{style::Style, themes::ColumnNames, Alignment, Color},
    Table, Tabled,
};

#[derive(Debug, Tabled)]
struct Function {
    declaration: String,
    name: String,
    return_type: String,
}

impl Function {
    fn new(decl: &str, name: &str, ret_type: &str) -> Self {
        Self {
            declaration: decl.to_string(),
            name: name.to_string(),
            return_type: ret_type.to_string(),
        }
    }
}

fn main() {
    #[rustfmt::skip]
    let data = vec![
        Function::new("struct stack *stack_create(int)", "stack_create", "struct stack *"),
        Function::new("void stack_destroy(struct stack *)", "stack_destroy", "void"),
        Function::new("int stack_put(struct stack *, vm_offset_t)", "stack_put", "int"),
        Function::new("void stack_copy(const struct stack *, struct stack *)", "stack_copy", "void"),
    ];

    let mut table = Table::new(data);

    table.with(Style::modern().remove_horizontal()).with(
        ColumnNames::default()
            .color(Color::BOLD | Color::BG_BLUE | Color::FG_WHITE)
            .alignment(Alignment::center()),
    );

    println!("{table}");
}