Last active
February 24, 2024 02:56
-
-
Save fancellu/184f36c18322016d6fe4af71fead4240 to your computer and use it in GitHub Desktop.
Rust simple CSV processing from a CV file, using csv crate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{error::Error, process}; | |
fn cities() -> Result<(), Box<dyn Error>> { | |
let mut csv_rdr = csv::Reader::from_path("data/cities.csv")?; | |
for result in csv_rdr.records() { | |
let record = result?; | |
println!("{:?}", record); | |
println!("{}",record.get(0).unwrap()); | |
} | |
Ok(()) | |
} | |
fn main() { | |
if let Err(err) = cities() { | |
println!("error running example: {}", err); | |
process::exit(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output
StringRecord(["Tokyo", "Kantō", "Japan", "37339000"])
Tokyo
StringRecord(["Delhi", "National Capital Territory", "India", "29341000"])
Delhi
StringRecord(["Shanghai", "Huadong", "China", "26446000"])
Shanghai
StringRecord(["São Paulo", "Southeast", "Brazil", "12325000"])
São Paulo
...