use alloc::string::{String, ToString};
use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Protocol {
ActivityPub,
ATProto,
Rss,
Web,
Custom(String),
}
impl fmt::Display for Protocol {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl Protocol {
pub fn as_str(&self) -> &str {
match self {
Self::ActivityPub => "activitypub",
Self::ATProto => "atproto",
Self::Rss => "rss",
Self::Web => "web",
Self::Custom(m) => m.as_str(),
}
}
}
impl<S> From<S> for Protocol
where
S: AsRef<str>,
{
fn from(s: S) -> Self {
match s.as_ref() {
"activitypub" => Self::ActivityPub,
"atproto" => Self::ATProto,
"rss" => Self::Rss,
"web" => Self::Web,
s => Self::Custom(s.to_string()),
}
}
}