Crates.io | csv-sniffer |
lib.rs | csv-sniffer |
version | 0.3.1 |
source | src |
created_at | 2018-03-23 22:07:26.33647 |
updated_at | 2022-03-20 17:51:19.371399 |
description | A CSV file format sniffer for Rust |
homepage | |
repository | https://github.com/jblondin/csv-sniffer |
max_upload_size | |
id | 57144 |
size | 54,544 |
This csv-sniffer
crate provides methods to infer CSV file details (delimiter choice, quote
character, number of fields, field data types, etc.). See the documentation for more details.
Add this to your Cargo.toml
:
[dependencies]
csv-sniffer = "0.1"
and this to your crate root:
extern crate csv_sniffer;
This example shows how to write a simple command-line tool for discovering the metadata of a CSV file:
extern crate csv_sniffer;
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
eprintln!("Usage: {} <file>", args[0]);
::std::process::exit(1);
}
// sniff the path provided by the first argument
match csv_sniffer::Sniffer::new().sniff_path(&args[1]) {
Ok(metadata) => {
println!("{}", metadata);
},
Err(err) => {
eprintln!("ERROR: {}", err);
}
}
}
This example is provided as the primary binary for this crate. In the source directory, this can be run as:
$ cargo run -- tests/data/library-visitors.csv