use std::error::Error;
use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
pub enum FontError {
Network(reqwest::Error),
Deserialize(serde_json::Error),
CacheDir(StringError),
CacheFile(std::io::Error),
}
impl Display for FontError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
FontError::Network(e) => write!(f, "font network error: {}", e),
FontError::Deserialize(e) => write!(f, "deserialization error: {}", e),
FontError::CacheDir(e) => write!(f, "font cache directory error: {}", e),
FontError::CacheFile(e) => write!(f, "font cache file error: {}", e),
}
}
}
impl Error for FontError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
FontError::Network(e) => Some(e),
FontError::Deserialize(e) => Some(e),
FontError::CacheDir(e) => Some(e),
FontError::CacheFile(e) => Some(e),
}
}
}
#[derive(Debug)]
pub struct StringError {
msg: String,
}
impl StringError {
pub fn new(msg: &str) -> Self {
Self {
msg: msg.to_string(),
}
}
}
impl Display for StringError {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "{}", self.msg)
}
}
impl Error for StringError {}