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
|
#[macro_use] extern crate tabprint;
use tabprint::Table;
use tabprint::row::Row;
use tabprint::cell::Cell;
/*
Following main function will print :
+---------+------+---------+
| ABC | DEFG | HIJKLMN |
+---------+------+---------+
| foobar | bar | foo |
+---------+------+---------+
| foobar2 | bar2 | foo2 |
+---------+------+---------+
Modified :
+---------+------+---------+
| ABC | DEFG | HIJKLMN |
+---------+------+---------+
| foobar | bar | foo |
+---------+------+---------+
| foobar2 | bar2 | new_foo |
+---------+------+---------+
*/
fn main() {
let mut table = Table::new(row!["ABC", "DEFG", "HIJKLMN"]);
table.add_row(row!["foobar", "bar", "foo"]).unwrap();
table.add_row(Row::new(vec![
Cell::new(&"foobar2".to_string()),
Cell::new(&"bar2".to_string()),
Cell::new(&"foo2".to_string())])
).unwrap();
table.printstd();
println!("Modified : ");
table.set_element(&"new_foo".to_string(), 2, 1).unwrap();
table.printstd();
// The same table can be built the following way :
let _table = table!(["ABC", "DEFG", "HIJKLMN"],
["foobar", "bar", "foo"],
["foobar2", "bar2", "foo2"]
);
}
|