use thiserror::Error;
#[derive(Debug, Error)]
pub enum CacheError {
#[error("键不存在: {key}")]
KeyNotFound { key: String },
#[error("值已过期")]
Expired,
#[error("缓存已满")]
CacheFull,
#[error("无效的配置: {0}")]
InvalidConfig(String),
}
impl CacheError {
pub fn is_not_found(&self) -> bool {
matches!(self, Self::KeyNotFound { .. })
}
pub fn is_expired(&self) -> bool {
matches!(self, Self::Expired)
}
}