summaryrefslogtreecommitdiffstats
path: root/examples/csv.rs
blob: 8dbaab1daf4967a27906684025388814ee2ae0f4 (plain)
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
extern crate prettytable;

/*
    Following main function will print :
    +---------+------+---------+
    | ABC     | DEFG | HIJKLMN |
    +---------+------+---------+
    | foobar  | bar  | foo     |
    +---------+------+---------+
    | foobar2 | bar2 | foo2    |
    +---------+------+---------+

    ABC,DEFG,HIJKLMN
    foobar,bar,foo
    foobar2,bar2,foo2
*/
#[cfg(feature = "csv")]
fn main() {
    use prettytable::Table;

    let table = Table::from_csv_string("ABC,DEFG,HIJKLMN\n\
                                        foobar,bar,foo\n\
                                        foobar2,bar2,foo2")
            .unwrap();
    table.printstd();

    println!("");
    println!("{}",
        String::from_utf8(table.to_csv(Vec::new()).unwrap().into_inner().unwrap()).unwrap());
}

#[cfg(not(feature = "csv"))]
fn main() {}