csv_scout/
lib.rs

1/*!
2This `csv-scout` crate provides methods to infer CSV file details (delimiter choice, quote
3character, number of fields, field data types, etc.).
4
5# Overview
6
7The [`Sniffer`](struct.Sniffer.html) type is the primary entry point for using this crate. Its
8[`Sniffer::open_path`](struct.Sniffer.html#method.open_path) and
9[`Sniffer::open_reader`](struct.Sniffer.html#method.open_reader) methods return a configured
10[`csv::Reader`](https://docs.rs/csv).
11
12Alternatively, the [`Sniffer::sniff_path`](struct.Sniffer.html#method.sniff_path) and
13[`Sniffer::sniff_reader`](struct.Sniffer.html#method.sniff_reader) methods return a
14[`Metadata`](metadata/struct.Metadata.html) object containing the deduced details about the
15underlying CSV input.
16
17This sniffer detects the following metadata about a CSV file:
18
19* Delimiter -- byte character between fields in a record
20* Quote -- byte character (either ", ', or `) used to quote fields, or that the file has no quotes
21
22See [`Metadata`](metadata/struct.Metadata.html) for full information about what the sniffer returns.
23
24# Setup
25
26Add this to your `Cargo.toml`:
27
28```toml
29[dependencies]
30csv-scout = "0.1"
31```
32
33# Example
34
35This example shows how to write a simple command-line tool for discovering the metadata of a CSV
36file:
37
38```no_run
39
40use std::env;
41
42fn main() {
43    let args: Vec<String> = env::args().collect();
44    if args.len() != 2 {
45        eprintln!("Usage: {} <file>", args[0]);
46        ::std::process::exit(1);
47    }
48
49    // sniff the path provided by the first argument
50    match csv_scout::Sniffer::new().sniff_path(&args[1]) {
51        Ok(metadata) => {
52            println!("{}", metadata);
53        },
54        Err(err) => {
55            eprintln!("ERROR: {}", err);
56        }
57    }
58}
59```
60
61This example is provided as the primary binary for this crate. In the source directory, this can be
62run as:
63
64```ignore
65$ cargo run -- tests/data/library-visitors.csv
66```
67
68*/
69
70#![warn(missing_docs)]
71
72pub(crate) mod chain;
73pub mod error;
74pub mod metadata;
75
76mod sniffer;
77pub use sniffer::Sniffer;
78
79mod sample;
80pub use sample::SampleSize;
81
82// mod field_type;
83// pub use field_type::{DatePreference, Type};
84
85// mod snip;