jacquard-api 0.12.0-beta.1

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: net.mimonelu.klearsky.extraFeed
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
/// Extra feed type for Klearsky. Used as an extension in app.bsky.actor.defs#savedFeedsPrefV2 items.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ExtraFeed<S: BosStr = DefaultStr> {
    Trending,
    Globalline,
    Other(S),
}

impl<S: BosStr> ExtraFeed<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Trending => "trending",
            Self::Globalline => "globalline",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "trending" => Self::Trending,
            "globalline" => Self::Globalline,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> AsRef<str> for ExtraFeed<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> core::fmt::Display for ExtraFeed<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> serde::Serialize for ExtraFeed<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: serde::Deserialize<'de> + BosStr> serde::Deserialize<'de> for ExtraFeed<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for ExtraFeed<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ExtraFeed<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ExtraFeed::Trending => ExtraFeed::Trending,
            ExtraFeed::Globalline => ExtraFeed::Globalline,
            ExtraFeed::Other(v) => ExtraFeed::Other(v.into_static()),
        }
    }
}