Skip to content

Instantly share code, notes, and snippets.

@nebuta nebuta/read_csv.rs
Last active Oct 1, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.