expression

Read CSV without a header row

Disable header handling for datasets where every row is data. Assign column meaning through a separately documented positional schema. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 2 pen Common mistake: Forgetting to disable headers and losing the first data record.

Formal Syntax & Structure

rust syntaxrust
ReaderBuilder::new().has_headers(false)

Working Example

Example Snippetrust
fn main() {    let mut r = csv::ReaderBuilder::new().has_headers(false).from_reader(&b"pen,2\nbook,3\n"[..]);    let rows: Vec<_> = r.records().collect::<Result<_, _>>().unwrap();    println!("{} {}", rows.len(), &rows[0][0]);}
Rust Reference