//! Caching support to prevent hitting the API a lot.
use std::{error::Error, fmt, fs, path::Path};
use xdg::BaseDirectories;
use super::APP_NAME;
#[derive(Debug)]
pub enum CacheError {
Io(std::io::Error),
}
error_froms! { CacheError,
err: std::io::Error => CacheError::Io(err),
}
impl fmt::Display for CacheError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
CacheError::Io(_) => write!(f, "cache input/output error"),
}
}
}
impl Error for CacheError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
CacheError::Io(ref err) => Some(err),
}
}
}
/// A generic cache.
pub trait Cache {
fn store(&mut self, path: &Path, data: &[u8]) -> Result<(), CacheError>;
fn get(&mut self, path: &Path) -> Result