use jacquard_common::CowStr;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ExtraFeed<'a> {
Trending,
Globalline,
Other(CowStr<'a>),
}
impl<'a> ExtraFeed<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Trending => "trending",
Self::Globalline => "globalline",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for ExtraFeed<'a> {
fn from(s: &'a str) -> Self {
match s {
"trending" => Self::Trending,
"globalline" => Self::Globalline,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for ExtraFeed<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"trending" => Self::Trending,
"globalline" => Self::Globalline,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> AsRef<str> for ExtraFeed<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> core::fmt::Display for ExtraFeed<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> serde::Serialize for ExtraFeed<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for ExtraFeed<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl jacquard_common::IntoStatic for ExtraFeed<'_> {
type Output = ExtraFeed<'static>;
fn into_static(self) -> Self::Output {
match self {
ExtraFeed::Trending => ExtraFeed::Trending,
ExtraFeed::Globalline => ExtraFeed::Globalline,
ExtraFeed::Other(v) => ExtraFeed::Other(v.into_static()),
}
}
}