Created
May 14, 2017 19:49
-
-
Save insipx/784896c710db9c7a0d78cf7415f29a50 to your computer and use it in GitHub Desktop.
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; | |
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