Last active
October 1, 2015 04:42
-
-
Save nebuta/b1faa390ad27566ba877 to your computer and use it in GitHub Desktop.
Reading a CSV file in Rust 1.3
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
extern crate csv; | |
extern crate rustc_serialize; | |
#[derive(RustcDecodable,Debug)] | |
struct Record { | |
id: i32, | |
x: f32, | |
y: f32, | |
} | |
fn main() { | |
let mut rdr = csv::Reader::from_file("/path/to/file.csv").unwrap().has_headers(true); | |
let mut rows: Vec<Record> = Vec::new(); | |
for record in rdr.decode() { | |
if let Ok(r) = record { | |
rows.push(r); | |
} | |
} | |
println!("{:?}", rows); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment