Skip to content

Instantly share code, notes, and snippets.

@insipx
Created May 14, 2017 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insipx/784896c710db9c7a0d78cf7415f29a50 to your computer and use it in GitHub Desktop.
Save insipx/784896c710db9c7a0d78cf7415f29a50 to your computer and use it in GitHub Desktop.
extern crate csv;
extern crate rustc_serialize;
pub struct Items {
pub ids: Vec<Item>,
csv_path: String,
}
#[derive(RustcDecodable)]
struct Item {
typeID: i64,
groupID: i64,
typeName: String,
description: Option<String>,
mass: u64,
volume: Option<i64>,
capacity: Option<i64>,
portionSize: Option<i64>,
raceID: Option<i64>,
basePrice: Option<i64>,
published: Option<i64>,
marketGroupID: Option<i64>,
iconID: Option<i64>,
soundID: Option<i64>,
graphicID: Option<i64>,
}
impl Items {
fn new(csv_path: String) -> Self {
Items {
ids: Vec::new(),
csv_path: csv_path,
}
}
fn parse_csv(&mut self) {
let mut rdr = csv::Reader::from_file(self.csv_path).has_headers(true);
self.ids = rdr.decode().collect::<csv::Result<Vec<Item>>>().unwrap();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment