5 unstable releases

Uses old Rust 2015

0.3.1 Mar 20, 2022
0.3.0 Mar 20, 2022
0.2.0 Mar 19, 2022
0.1.1 Mar 24, 2018
0.1.0 Mar 23, 2018

#1891 in Parser implementations

Download history 163/week @ 2024-07-22 200/week @ 2024-07-29 114/week @ 2024-08-05 207/week @ 2024-08-12 443/week @ 2024-08-19 211/week @ 2024-08-26 271/week @ 2024-09-02 539/week @ 2024-09-09 291/week @ 2024-09-16 477/week @ 2024-09-23 371/week @ 2024-09-30 350/week @ 2024-10-07 492/week @ 2024-10-14 615/week @ 2024-10-21 508/week @ 2024-10-28 889/week @ 2024-11-04

2,552 downloads per month
Used in 5 crates (4 directly)

MIT license

47KB
956 lines

CSV Sniffer

Build Status Documentation

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.

Setup

Add this to your Cargo.toml:

[dependencies]
csv-sniffer = "0.1"

and this to your crate root:

extern crate csv_sniffer;

Example

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

Dependencies

~3.5–5MB
~75K SLoC