From 4010e0f5abb28bae3207c78dba74f0896eedea51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 29 Oct 2020 21:28:12 +0100 Subject: cargo fmt --- mumlib/src/config.rs | 61 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 25 deletions(-) (limited to 'mumlib/src/config.rs') diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index 5c37a2b..e6b97fd 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -1,9 +1,9 @@ use serde::{Deserialize, Serialize}; use std::convert::TryFrom; use std::fs; -use toml::Value; -use toml::value::Array; use std::path::Path; +use toml::value::Array; +use toml::Value; #[derive(Debug, Deserialize, Serialize)] struct TOMLConfig { @@ -19,7 +19,11 @@ pub struct Config { impl Config { pub fn write_default_cfg(&self, create: bool) -> Result<(), std::io::Error> { - let path = if create { get_creatable_cfg_path() } else { get_cfg_path() }; + let path = if create { + get_creatable_cfg_path() + } else { + get_cfg_path() + }; let path = std::path::Path::new(&path); // Possible race here. It's fine since it shows when: // 1) the file doesn't exist when checked and is then created @@ -33,7 +37,10 @@ impl Config { return Ok(()); } - fs::write(path, toml::to_string(&TOMLConfig::from(self.clone())).unwrap()) + fs::write( + path, + toml::to_string(&TOMLConfig::from(self.clone())).unwrap(), + ) } } @@ -107,11 +114,15 @@ impl TryFrom for Config { fn try_from(config: TOMLConfig) -> Result { Ok(Config { audio: config.audio, - servers: config.servers.map(|servers| servers - .into_iter() - .map(|s| s.try_into::()) - .collect()) - .transpose()?, + servers: config + .servers + .map(|servers| { + servers + .into_iter() + .map(|s| s.try_into::()) + .collect() + }) + .transpose()?, }) } } @@ -120,25 +131,25 @@ impl From for TOMLConfig { fn from(config: Config) -> Self { TOMLConfig { audio: config.audio, - servers: config.servers.map(|servers| servers - .into_iter() - .map(|s| Value::try_from::(s).unwrap()) - .collect()), + servers: config.servers.map(|servers| { + servers + .into_iter() + .map(|s| Value::try_from::(s).unwrap()) + .collect() + }), } } } pub fn read_default_cfg() -> Option { - Some(Config::try_from( - toml::from_str::( - &match fs::read_to_string(get_cfg_path()) { - Ok(f) => { - f.to_string() - }, - Err(_) => { - return None - } - } - ).expect("invalid TOML in config file") //TODO - ).expect("invalid config in TOML")) //TODO + Some( + Config::try_from( + toml::from_str::(&match fs::read_to_string(get_cfg_path()) { + Ok(f) => f.to_string(), + Err(_) => return None, + }) + .expect("invalid TOML in config file"), //TODO + ) + .expect("invalid config in TOML"), + ) //TODO } -- cgit v1.2.1