Crate csv_to_table

source ·
Expand description

A library which provides a CSV input abstraction for tabled. It relies on csv library.

Example

let csv = "name,designed_by,invented_year\n\
           C,Dennis Ritchie,1972\n\
           Rust,Graydon Hoare,2010\n\
           Go,Rob Pike,2009";

let table = csv_to_table::from_reader(csv.as_bytes()).unwrap().to_string();

let expected = "+------+----------------+---------------+\n\
                | name | designed_by    | invented_year |\n\
                +------+----------------+---------------+\n\
                | C    | Dennis Ritchie | 1972          |\n\
                +------+----------------+---------------+\n\
                | Rust | Graydon Hoare  | 2010          |\n\
                +------+----------------+---------------+\n\
                | Go   | Rob Pike       | 2009          |\n\
                +------+----------------+---------------+";

assert_eq!(table, expected);

You can also use iter to build an table from Iterator. It is usefull when you have a huge csv and don’t want to load it all along into memory. But it’s interface might be a little bit less feature full cause of its limitations.

let csv = "name,designed_by,invented_year\n\
           C,Dennis Ritchie,1972\n\
           Rust,Graydon Hoare,2010\n\
           Go,Rob Pike,2009";

let table = csv_to_table::iter::from_reader(csv.as_bytes()).to_string();

let expected = "+------+----------------+---------------+\n\
                | name | designed_by    | invented_year |\n\
                +------+----------------+---------------+\n\
                | C    | Dennis Ritchie | 1972          |\n\
                +------+----------------+---------------+\n\
                | Rust | Graydon Hoare  | 2010          |\n\
                +------+----------------+---------------+\n\
                | Go   | Rob Pike       | 2009          |\n\
                +------+----------------+---------------+";

assert_eq!(table, expected);

Modules

Functions