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