Skip to main content

CsvReader

Struct CsvReader 

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

CSV file reader with streaming capabilities and decompression support

Reads CSV files row by row using an iterator pattern. Automatically handles compressed files (.csv.zst, .csv.gz, .csv.zip). Memory usage is constant and low.

§Examples

use excelstream::csv_reader::CsvReader;

let mut reader = CsvReader::open("data.csv").unwrap();

for row_result in reader.rows() {
    let row = row_result.unwrap();
    println!("{:?}", row);
}

§With Headers

use excelstream::csv_reader::CsvReader;

let mut reader = CsvReader::open("data.csv")
    .unwrap()
    .has_header(true);

if let Some(headers) = reader.headers() {
    println!("Headers: {:?}", headers);
}

for row_result in reader.rows() {
    let row = row_result.unwrap();
    // Process data rows (header already consumed)
}

Implementations§

Source§

impl CsvReader

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open CSV file - auto-detects compression from file extension

§File Extensions
  • .csv → Uncompressed, direct read
  • .csv.zst, .csv.zip → Zstd decompression
  • .csv.gz → Deflate/Gzip decompression
§Examples
use excelstream::csv_reader::CsvReader;

// Plain CSV
let reader = CsvReader::open("data.csv").unwrap();

// Compressed CSV (auto-detected)
let reader = CsvReader::open("data.csv.zst").unwrap();
Source

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

Set custom delimiter (builder pattern)

§Examples
use excelstream::csv_reader::CsvReader;

let reader = CsvReader::open("data.csv")
    .unwrap()
    .delimiter(b';');
Source

pub fn quote_char(self, quote: u8) -> Self

Set custom quote character (builder pattern)

Source

pub fn has_header(self, has: bool) -> Self

Indicate that the first row contains headers (builder pattern)

When set to true, the first row will be stored and accessible via headers(). The iterator will skip the header row.

Source

pub fn headers(&self) -> Option<&[String]>

Get header row if available

Returns Some(&[String]) if headers were parsed, None otherwise.

Source

pub fn read_row(&mut self) -> Result<Option<Vec<String>>>

Read a single row

Returns Ok(None) when EOF is reached.

§Examples
use excelstream::csv_reader::CsvReader;

let mut reader = CsvReader::open("data.csv").unwrap();

while let Some(row) = reader.read_row().unwrap() {
    println!("{:?}", row);
}
Source

pub fn rows(&mut self) -> CsvRowIterator<'_>

Get iterator over rows

§Examples
use excelstream::csv_reader::CsvReader;

let mut reader = CsvReader::open("data.csv").unwrap();

for row_result in reader.rows() {
    let row = row_result.unwrap();
    println!("{:?}", row);
}
Source

pub fn row_count(&self) -> u64

Get the number of rows read so far

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, 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.