diff options
Diffstat (limited to 'src/useropts.rs')
-rw-r--r-- | src/useropts.rs | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/src/useropts.rs b/src/useropts.rs index 27e14df..2e38f05 100644 --- a/src/useropts.rs +++ b/src/useropts.rs @@ -11,45 +11,22 @@ use image::Rgba; use rusttype::Font; use serde::{Deserialize, Serialize}; -use std::{error::Error, fmt, fs, io, path::Path}; +use std::{fs, io, path::Path}; +use thiserror::Error; use super::render::{Alignment, RenderOptions}; /// Error that can occur during loading or converting user options. -#[derive(Debug)] +#[derive(Error, Debug)] pub enum ConfigError { - Io(io::Error), - Serialization(toml::de::Error), + #[error("I/O error")] + Io(#[from] io::Error), + #[error("Deserialization error")] + Serialization(#[from] toml::de::Error), + #[error("Font loading error")] Font, } -error_froms! { - ConfigError, - err: io::Error => ConfigError::Io(err), - err: toml::de::Error => ConfigError::Serialization(err), -} - -impl fmt::Display for ConfigError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "ConfigError: ")?; - match *self { - ConfigError::Io(_) => write!(f, "input/output error"), - ConfigError::Serialization(_) => write!(f, "serialization error"), - ConfigError::Font => write!(f, "could not load the font"), - } - } -} - -impl Error for ConfigError { - fn source(&self) -> Option<&(dyn Error + 'static)> { - match *self { - ConfigError::Io(ref err) => Some(err), - ConfigError::Serialization(ref err) => Some(err), - ConfigError::Font => None, - } - } -} - macro_rules! maybe_take_from { (from: $from:expr, to: $to:ident, $($field:ident,)*) => { $( |