How to use csv crate in Rust CSV parser

Install the csv crate via Cargo and use ReaderBuilder to parse CSV files into records or structs.

Add the csv crate to your Cargo.toml and use Reader::from_path to parse files into records or structs.

[dependencies]
csv = "1.3"
use csv::ReaderBuilder;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let mut reader = ReaderBuilder::new().from_path("data.csv")?;
    for result in reader.records() {
        let record = result?;
        println!("{:?}", record);
    }
    Ok(())
}