Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate csv; // 1.0.2
- extern crate serde; // 1.0.80
- use std::io;
- use std::fs::File;
- use std::path::Path;
- use serde::Deserialize;
- fn load_csv<T, P: AsRef<Path>>(path: P) -> io::Result<impl Iterator<Item=csv::Result<T>>> where T: for<'a> Deserialize<'a> {
- let file = File::open(path)?;
- Ok(csv::Reader::from_reader(file).into_deserialize())
- }
- fn main() {
- let cities = load_csv("/Users/dominik/Downloads/world-cities_csv.csv").expect("Failed to open file").collect::<Result<Vec<String>, _>>().expect("Filed to load file");
- }
Add Comment
Please, Sign In to add comment