diff --git a/cosmic-config/src/lib.rs b/cosmic-config/src/lib.rs index 20e03a5..e3d8213 100644 --- a/cosmic-config/src/lib.rs +++ b/cosmic-config/src/lib.rs @@ -9,7 +9,7 @@ use notify::{ use serde::{de::DeserializeOwned, Serialize}; use std::{ borrow::Cow, - fs, + fmt, fs, hash::Hash, io::Write, path::{Path, PathBuf}, @@ -33,6 +33,22 @@ pub enum Error { RonSpanned(ron::error::SpannedError), } +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::AtomicWrites(err) => err.fmt(f), + Self::InvalidName(name) => write!(f, "invalid config name '{}'", name), + Self::Io(err) => err.fmt(f), + Self::NoConfigDirectory => write!(f, "cosmic config directory not found"), + Self::Notify(err) => err.fmt(f), + Self::Ron(err) => err.fmt(f), + Self::RonSpanned(err) => err.fmt(f), + } + } +} + +impl std::error::Error for Error {} + impl From> for Error { fn from(f: atomicwrites::Error) -> Self { Self::AtomicWrites(f)