Guest User

Untitled

a guest
Dec 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. extern crate csv; // 1.0.2
  2. extern crate serde; // 1.0.80
  3.  
  4. use std::io;
  5. use std::fs::File;
  6. use std::path::Path;
  7. use serde::Deserialize;
  8.  
  9. fn load_csv<T, P: AsRef<Path>>(path: P) -> io::Result<impl Iterator<Item=csv::Result<T>>> where T: for<'a> Deserialize<'a> {
  10. let file = File::open(path)?;
  11. Ok(csv::Reader::from_reader(file).into_deserialize())
  12. }
  13.  
  14. fn main() {
  15. 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");
  16. }
Add Comment
Please, Sign In to add comment