custom_data/
custom_data.rs

1use tabprinter::{Alignment, Table, TableStyle, Cell};
2
3struct Person {
4    name: String,
5    age: u32,
6    city: String,
7}
8
9fn main() {
10    // Create a list of people
11    let people = vec![
12        Person {
13            name: "Alice".to_string(),
14            age: 30,
15            city: "New York".to_string(),
16        },
17        Person {
18            name: "Bob".to_string(),
19            age: 25,
20            city: "Los Angeles".to_string(),
21        },
22        Person {
23            name: "Charlie".to_string(),
24            age: 35,
25            city: "Chicago".to_string(),
26        },
27    ];
28
29    // Create a new table with the FancyGrid style
30    let mut table = Table::new(TableStyle::FancyGrid);
31
32    // Add columns to the table
33    table.add_column("Name",Alignment::Left);
34    table.add_column("Age", Alignment::Right);
35    table.add_column("City",Alignment::Center);
36
37    // Add rows to the table using the list of people
38    for person in people {
39        table.add_row(vec![
40            Cell::new(&person.name),
41            Cell::new(&person.age.to_string()),
42            Cell::new(&person.city),
43        ]);
44    }
45
46    // Print the table
47    table.print().unwrap();
48}