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 +++++++++++++++++++++++++++++++--------------------- mumlib/src/error.rs | 5 +++-- mumlib/src/lib.rs | 3 ++- 3 files changed, 41 insertions(+), 28 deletions(-) (limited to 'mumlib/src') 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 } diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index a4c6dcb..c6d9255 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -12,14 +12,15 @@ pub enum Error { InvalidServerAddrError(String, u16), } - impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { Error::DisconnectedError => write!(f, "Not connected to a server"), Error::AlreadyConnectedError => write!(f, "Already connected to a server"), Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id), - Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}: {}", addr, port), + Error::InvalidServerAddrError(addr, port) => { + write!(f, "Invalid server address: {}: {}", addr, port) + } } } } diff --git a/mumlib/src/lib.rs b/mumlib/src/lib.rs index 93b7682..a54990e 100644 --- a/mumlib/src/lib.rs +++ b/mumlib/src/lib.rs @@ -30,7 +30,8 @@ pub fn setup_logger>(target: T, color: bool) { Level::Info => "INFO ", Level::Debug => "DEBUG", Level::Trace => "TRACE", - }.normal() + } + .normal() }, record.file().unwrap(), record.line().unwrap(), -- cgit v1.2.1