expression

CSV record width validation

The default reader checks equal field counts across records. Flexible parsing permits different widths, so callers must validate their own shape. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): true 1 Common mistake: Enabling flexible mode without checking missing required columns.

Formal Syntax & Structure

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

Working Example

Example Snippetrust
fn main() {    let input = &b"a,b\n1,2\n3\n"[..];    let mut strict = csv::Reader::from_reader(input);    println!("{}", strict.records().nth(1).unwrap().is_err());    let mut flexible = csv::ReaderBuilder::new().flexible(true).from_reader(input);    println!("{}", flexible.records().nth(1).unwrap().unwrap().len());}
Rust Reference