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
impl CsvReader
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
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();Sourcepub fn delimiter(self, delim: u8) -> Self
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';');Sourcepub fn quote_char(self, quote: u8) -> Self
pub fn quote_char(self, quote: u8) -> Self
Set custom quote character (builder pattern)
Sourcepub fn has_header(self, has: bool) -> Self
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.
Sourcepub fn headers(&self) -> Option<&[String]>
pub fn headers(&self) -> Option<&[String]>
Get header row if available
Returns Some(&[String]) if headers were parsed, None otherwise.
Sourcepub fn read_row(&mut self) -> Result<Option<Vec<String>>>
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);
}Sourcepub fn rows(&mut self) -> CsvRowIterator<'_> ⓘ
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);
}Auto Trait Implementations§
impl Freeze for CsvReader
impl !RefUnwindSafe for CsvReader
impl !Send for CsvReader
impl !Sync for CsvReader
impl Unpin for CsvReader
impl !UnwindSafe for CsvReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more