use std::str::FromStr;
use serde::{Serialize, Deserialize};
use crate::util::*;
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Suitability)]
#[serde(deny_unknown_fields)]
#[serde(remote = "Self")]
pub enum CachePath {
#[default]
Memory,
Path(String)
}
crate::util::string_or_struct_magic!(CachePath);
impl CachePath {
pub fn as_str(&self) -> &str {
match self {
Self::Memory => ":memory:",
Self::Path(x) => x
}
}
}
impl AsRef<str> for CachePath {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl FromStr for CachePath {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(s.into())
}
}
impl From<&str> for CachePath {
fn from(value: &str) -> Self {
value.to_string().into()
}
}
impl From<String> for CachePath {
fn from(value: String) -> Self {
match &*value {
":memory:" => Self::Memory,
_ => Self::Path(value)
}
}
}