From 9f40abc02552a3c3ad510db428b342df1b65b5b9 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Sat, 28 Dec 2019 22:43:13 -0500 Subject: [PATCH] added config deserializing --- src/config.rs | 30 ++++++++++++++++++++++++++++++ src/main.rs | 24 +++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index e69de29..a219f54 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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 +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..35a50fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() { - println!("Hello, world!"); + let configuration = config::init_config(); + println!("{:?}", configuration.ipaddr); }