diff options
Diffstat (limited to 'pkgs/by-name/mp/mpdpopm/src/config.rs')
| -rw-r--r-- | pkgs/by-name/mp/mpdpopm/src/config.rs | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/pkgs/by-name/mp/mpdpopm/src/config.rs b/pkgs/by-name/mp/mpdpopm/src/config.rs index 08509e47..e6c01599 100644 --- a/pkgs/by-name/mp/mpdpopm/src/config.rs +++ b/pkgs/by-name/mp/mpdpopm/src/config.rs @@ -40,9 +40,10 @@ //! bundle-up all the errors, report 'em & urge the user to use the most recent version use crate::vars::{LOCALSTATEDIR, PREFIX}; +use anyhow::{Result, bail}; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; +use std::{env, path::PathBuf}; /// [mpdpopm](crate) can communicate with MPD over either a local Unix socket, or over regular TCP #[derive(Debug, Deserialize, PartialEq, Serialize)] @@ -85,15 +86,6 @@ mod test_connection { } } -impl std::default::Default for Connection { - fn default() -> Self { - Connection::TCP { - host: String::from("localhost"), - port: 6600, - } - } -} - /// This is the most recent `mppopmd` configuration struct. #[derive(Deserialize, Debug, Serialize)] #[serde(default)] @@ -139,31 +131,11 @@ impl Default for Config { } } -#[derive(Debug)] -pub enum Error { - /// Failure to parse - ParseFail { err: Box<dyn std::error::Error> }, -} - -impl std::fmt::Display for Error { - #[allow(unreachable_patterns)] // the _ arm is *currently* unreachable - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self { - Error::ParseFail { err } => write!(f, "Parse failure: {}", err), - _ => write!(f, "Unknown configuration error"), - } - } -} - -pub type Result<T> = std::result::Result<T, Error>; - pub fn from_str(text: &str) -> Result<Config> { let cfg: Config = match serde_json::from_str(text) { Ok(cfg) => cfg, Err(err_outer) => { - return Err(Error::ParseFail { - err: Box::new(err_outer), - }); + bail!("Failed to parse config: `{}`", err_outer) } }; Ok(cfg) |
