use crate::prelude::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StoreError {
NotFound,
Expired,
WrongType,
}
impl std::fmt::Display for StoreError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NotFound => write!(f, "Key not found"),
Self::Expired => write!(f, "Key expired"),
Self::WrongType => write!(f, "Wrong type"),
}
}
}
impl std::error::Error for StoreError {}
impl StoreError {
#[must_use]
pub fn to_value(self) -> Value {
match self {
Self::NotFound | Self::Expired => Value::Nil,
Self::WrongType => Value::Error(
"WRONGTYPE Operation against a key holding the wrong kind of value".into(),
),
}
}
}
impl From<StoreError> for Value {
fn from(err: StoreError) -> Self {
err.to_value()
}
}