From 6269372d8f4fc893d1679e6c56d66aefe24c6588 Mon Sep 17 00:00:00 2001 From: jan Date: Sat, 1 Oct 2016 19:12:39 +0200 Subject: serde diff --git a/Cargo.toml b/Cargo.toml index 517a6b1..8d5f0b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,7 @@ authors = ["jan "] regex = "0.1" walkdir = "0.1" yaml-rust = "0.3" + +serde = "0.8" +serde_derive = "0.8" +serde_json = "0.8" diff --git a/src/character.rs b/src/character.rs index b0322dd..c1d3829 100644 --- a/src/character.rs +++ b/src/character.rs @@ -9,26 +9,26 @@ use super::tiles; use std::collections::HashMap; -#[derive(Debug)] +#[derive(Debug, Serialize)] pub struct Names { pub romaji: String, pub japanese: String, pub aliases: Vec, } -#[derive(Debug)] +#[derive(Debug, Serialize)] pub struct Images { pub thumb: String, pub full: String, } -#[derive(Debug)] +#[derive(Debug, Serialize)] pub struct Traits { pub official: Vec, pub indexed: Vec, } -#[derive(Debug)] +#[derive(Debug, Serialize)] pub struct Character { pub name: Names, pub image: Images, diff --git a/src/dl_list.rs b/src/dl_list.rs index 979c332..3327388 100644 --- a/src/dl_list.rs +++ b/src/dl_list.rs @@ -1,6 +1,6 @@ use super::regex::Regex; -#[derive(Debug)] +#[derive(Debug, Serialize)] pub struct DLListItem { name: String, value: String, diff --git a/src/main.rs b/src/main.rs index ea89b02..a7f1f9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ +#![feature(rustc_macro)] +#[macro_use] extern crate serde_derive; +extern crate serde_json; + extern crate regex; extern crate yaml_rust; @@ -21,7 +25,9 @@ mod tiles; fn main() { let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); + let out_files = env::var("OUT").unwrap_or("json".into()); let base_path = Path::new(&raw_files); + let out_path = Path::new(&out_files); for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { @@ -36,6 +42,10 @@ fn main() { let mut char = Character::new(); char.parse(&buf); - println!("{:?}", char); + + let json = serde_json::to_string(&char).unwrap(); + + let mut o = File::create(out_path.join(entry.file_name())).unwrap(); + o.write_all(json.as_bytes()).unwrap(); } } diff --git a/src/tags.rs b/src/tags.rs index 0fdf815..561c54d 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -2,7 +2,7 @@ use super::regex::Regex; use std::str::FromStr; -#[derive(Debug)] +#[derive(Debug, Serialize)] pub struct Tag { pub id: u32, pub name: String, -- cgit v0.10.1