Sniffer

Struct Sniffer 

Source
pub struct Sniffer { /* private fields */ }
Expand description

A CSV sniffer.

The sniffer examines a CSV file, passed in either through a file or a reader.

Implementations§

Source§

impl Sniffer

Source

pub fn new() -> Self

Create a new CSV sniffer.

Examples found in repository?
examples/sniff_gdp.rs (line 12)
7fn main() {
8    let data_filepath = Path::new(file!())
9        .parent()
10        .unwrap()
11        .join("../tests/data/gdp.csv");
12    let dialect = Sniffer::new()
13        .sample_size(SampleSize::All)
14        .sniff_path(data_filepath)
15        .unwrap();
16    println!("{dialect:#?}");
17}
Source

pub fn delimiter(&mut self, delimiter: u8) -> &mut Self

Specify the delimiter character.

Source

pub fn quote(&mut self, quote: Quote) -> &mut Self

Specify the header type (whether the CSV file has a header row, and where the data starts). Specify the quote character (if any), and whether two quotes in a row as to be interpreted as an escaped quote.

Source

pub fn sample_size(&mut self, sample_size: SampleSize) -> &mut Self

The size of the sample to examine while sniffing. If using SampleSize::Records, the sniffer will use the Terminator::CRLF as record separator.

The sample size defaults to SampleSize::Bytes(4096).

Examples found in repository?
examples/sniff_gdp.rs (line 13)
7fn main() {
8    let data_filepath = Path::new(file!())
9        .parent()
10        .unwrap()
11        .join("../tests/data/gdp.csv");
12    let dialect = Sniffer::new()
13        .sample_size(SampleSize::All)
14        .sniff_path(data_filepath)
15        .unwrap();
16    println!("{dialect:#?}");
17}
Source

pub fn open_path<P: AsRef<Path>>(&mut self, path: P) -> Result<Reader<File>>

Sniff the CSV file located at the provided path, and return a Reader (from the csv crate) ready to ready the file.

Fails on file opening or rendering errors, or on an error examining the file.

Source

pub fn open_reader<R: Read + Seek>(&mut self, reader: R) -> Result<Reader<R>>

Sniff the CSV file provided by the reader, and return a csv Reader object.

Fails on file opening or rendering errors, or on an error examining the file.

Source

pub fn sniff_path<P: AsRef<Path>>(&mut self, path: P) -> Result<Metadata>

Sniff the CSV file located at the provided path, and return a Metadata object containing information about the CSV file.

Fails on file opening or rendering errors, or on an error examining the file.

Examples found in repository?
examples/sniff_gdp.rs (line 14)
7fn main() {
8    let data_filepath = Path::new(file!())
9        .parent()
10        .unwrap()
11        .join("../tests/data/gdp.csv");
12    let dialect = Sniffer::new()
13        .sample_size(SampleSize::All)
14        .sniff_path(data_filepath)
15        .unwrap();
16    println!("{dialect:#?}");
17}
Source

pub fn sniff_reader<R: Read + Seek>(&mut self, reader: R) -> Result<Metadata>

Sniff the CSV file provider by the reader, and return a Metadata object containing information about the CSV file.

Fails on file opening or readering errors, or on an error examining the file.

Trait Implementations§

Source§

impl Debug for Sniffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Sniffer

Source§

fn default() -> Sniffer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.