Reading and writing of tabular data.
- DSV (Delimiter-separated values): CSV (comma-separated values), TSV (tab-separated values)
- Fixed width: formats with columns of fixed width
Add this to your Cargo.toml:
[dependencies.tabular]
git = "https://github.com/arjantop/rust-tabular.git"
Reading CSV data:
use std::io::BufferedReader;
use std::io::File;
use tabular::dsv::{read_rows, CSV};
let path = Path::new("file.csv");
let mut file = BufferedReader::new(File::open(&path));
for row in read_rows(CSV, file) {
println!("row = {}", row)
}
Reading fixed-length column data:
use std::io::BufferedReader;
use std::io::File;
use tabular::fixed::{Config, Newline, LF, ColumnConfig, Left, Right, read_rows};
let path = Path::new("file.csv");
let mut file = BufferedReader::new(File::open(&path));
let config = Config {
columns: vec!(ColumnConfig {width: 5, pad_with: ' ', justification: Left},
ColumnConfig {width: 9, pad_with: '-', justification: Right}),
line_end: Newline(LF)
};
for row in read_rows(config, file) {
println!("row = {}", row)
}
API documentation on rust-ci.org
git clone https://github.com/arjantop/rust-tabular
cd rust-tabular
make