use serde::{Deserialize, Serialize};
use std::ops::Deref;
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PurePath(pub String);
impl Deref for PurePath {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PathWithLocale(pub String);
impl Deref for PathWithLocale {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PathWithoutLocale(pub String);
impl Deref for PathWithoutLocale {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PathMaybeWithLocale(pub String);
impl Deref for PathMaybeWithLocale {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl PathMaybeWithLocale {
pub fn new(path_without_locale: &PathWithoutLocale, locale: &str) -> Self {
Self(match locale {
"xx-XX" => path_without_locale.to_string(),
locale => format!("{}/{}", locale, path_without_locale.0),
})
}
}