basic/basic.rs
1use prettytable::{ptable, row, table, Cell, Row, Table};
2
3/*
4 Following main function will print :
5 +---------+------+---------+
6 | ABC | DEFG | HIJKLMN |
7 +---------+------+---------+
8 | foobar | bar | foo |
9 +---------+------+---------+
10 | foobar2 | bar2 | foo2 |
11 +---------+------+---------+
12 Modified :
13 +---------+------+---------+
14 | ABC | DEFG | HIJKLMN |
15 +---------+------+---------+
16 | foobar | bar | foo |
17 +---------+------+---------+
18 | foobar2 | bar2 | new_foo |
19 +---------+------+---------+
20*/
21fn main() {
22 let mut table = Table::new();
23 table.add_row(row!["ABC", "DEFG", "HIJKLMN"]);
24 table.add_row(row!["foobar", "bar", "foo"]);
25 table.add_row(Row::new(vec![
26 Cell::new("foobar2"),
27 Cell::new("bar2"),
28 Cell::new("foo2"),
29 ]));
30 table.printstd();
31 println!("Modified : ");
32 table.set_element("new_foo", 2, 1).unwrap();
33 table.printstd();
34
35 // The same table can be built the following way :
36 let _table = table!(
37 ["ABC", "DEFG", "HIJKLMN"],
38 ["foobar", "bar", "foo"],
39 ["foobar2", "bar2", "foo2"]
40 );
41
42 // Or directly print it like this
43 let _table = ptable!(
44 ["ABC", "DEFG", "HIJKLMN"],
45 ["foobar", "bar", "foo"],
46 ["foobar2", "bar2", "foo2"]
47 );
48}