Skip to content

Instantly share code, notes, and snippets.

@nebuta
Last active October 1, 2015 04:42
Show Gist options
  • Save nebuta/b1faa390ad27566ba877 to your computer and use it in GitHub Desktop.
Save nebuta/b1faa390ad27566ba877 to your computer and use it in GitHub Desktop.
Reading a CSV file in Rust 1.3
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