From 7eef7ad915a608f5cad510d079b9240ed11698f1 Mon Sep 17 00:00:00 2001 From: Hristo Venev Date: Tue, 19 Mar 2019 10:30:17 +0200 Subject: BREAKING CHANGE: The config file is now in toml. The "sources" field is now [[source]]. --- src/config.rs | 1 + src/main.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 00874c2..cd874da 100644 --- a/src/config.rs +++ b/src/config.rs @@ -40,6 +40,7 @@ pub struct Config { #[serde(flatten)] pub update_config: UpdateConfig, + #[serde(rename = "source")] pub sources: Vec, } diff --git a/src/main.rs b/src/main.rs index f5ebb26..d556064 100644 --- a/src/main.rs +++ b/src/main.rs @@ -204,13 +204,19 @@ fn fetch_source(url: &str) -> io::Result { } fn load_config(path: &str) -> io::Result { - use serde_json; + use toml; use std::fs; - let config_file = fs::File::open(path)?; - let rd = io::BufReader::new(config_file); - let mut de = serde_json::Deserializer::from_reader(rd); - Ok(serde::Deserialize::deserialize(&mut de)?) + let mut data = String::new(); + { + use io::Read; + let mut config_file = fs::File::open(path)?; + config_file.read_to_string(&mut data)?; + } + let mut de = toml::Deserializer::new(&data); + serde::Deserialize::deserialize(&mut de).map_err(|e| { + io::Error::new(io::ErrorKind::InvalidData, e) + }) } fn main() { -- cgit