use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Key not found: {0}")]
NotFound(String),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Deserialization error: {0}")]
Deserialization(String),
#[error("Connection error: {0}")]
Connection(String),
#[error("Store not configured: {0}")]
StoreNotConfigured(String),
#[cfg(feature = "redis-backend")]
#[error("Redis error: {0}")]
Redis(#[from] redis::RedisError),
}
impl Error {
pub fn not_found(key: impl Into<String>) -> Self {
Self::NotFound(key.into())
}
pub fn serialization(msg: impl Into<String>) -> Self {
Self::Serialization(msg.into())
}
pub fn deserialization(msg: impl Into<String>) -> Self {
Self::Deserialization(msg.into())
}
pub fn connection(msg: impl Into<String>) -> Self {
Self::Connection(msg.into())
}
pub fn store_not_configured(store: impl Into<String>) -> Self {
Self::StoreNotConfigured(store.into())
}
}