url_cleaner_engine/glue/caching/
path.rs1use std::str::FromStr;
4
5use serde::{Serialize, Deserialize};
6
7use crate::util::*;
8
9#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Suitability)]
11#[serde(deny_unknown_fields)]
12#[serde(remote = "Self")]
13pub enum CachePath {
14 #[default]
18 Memory,
19 Path(String)
21}
22
23crate::util::string_or_struct_magic!(CachePath);
24
25impl CachePath {
26 pub fn as_str(&self) -> &str {
38 match self {
39 Self::Memory => ":memory:",
40 Self::Path(x) => x
41 }
42 }
43}
44
45impl AsRef<str> for CachePath {
46 fn as_ref(&self) -> &str {
47 self.as_str()
48 }
49}
50
51impl FromStr for CachePath {
52 type Err = std::convert::Infallible;
53
54 fn from_str(s: &str) -> Result<Self, Self::Err> {
55 Ok(s.into())
56 }
57}
58
59impl From<&str> for CachePath {
60 fn from(value: &str) -> Self {
61 value.to_string().into()
62 }
63}
64
65impl From<String> for CachePath {
66 fn from(value: String) -> Self {
67 match &*value {
68 ":memory:" => Self::Memory,
69 _ => Self::Path(value)
70 }
71 }
72}