added config deserializing

This commit is contained in:
Wyatt J. Miller 2019-12-28 22:43:13 -05:00
parent a87f6ac3d3
commit 9f40abc025
2 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,30 @@
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
use std::fs::File;
use std::io::{BufReader, Read};
use std::path::Path;
use serde::Deserialize;
use serde_json::Result;
// config structure
#[derive(Deserialize, Debug)]
pub struct Configuration {
pub ipaddr: String,
pub port: i32,
pub tv: String,
pub active_app: String,
}
// grab the config
pub fn init_config() -> Configuration {
let mut file = File::open(&Path::new("config.json")).expect("Couldn't grab JSON!");
let mut data = String::new();
file.read_to_string(&mut data).expect("Poop");
let config: Configuration = serde_json::from_str(&data).expect("Couldn't parse JSON!");
config
}

View File

@ -1,3 +1,25 @@
// external crates getting imported
extern crate ureq;
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
extern crate xml;
// standard library stuff
use std::fs::File;
use std::io::{BufReader, Read};
// actual third party library being imported
use serde::{Deserialize, Serialize};
use serde_json::Result;
use xml::reader::{EventReader, XmlEvent};
// local files that need to be imported
mod app;
mod config;
mod generate;
fn main() { fn main() {
println!("Hello, world!"); let configuration = config::init_config();
println!("{:?}", configuration.ipaddr);
} }