use alloc::string::String;
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 {
match self {
Self::ActivityPub => write!(f, "activitypub"),
Self::ATProto => write!(f, "atproto"),
Self::Rss => write!(f, "rss"),
Self::Web => write!(f, "web"),
Self::Custom(m) => write!(f, "{m}"),
}
}
}
impl<S> From<S> for Protocol
where
S: Into<String>,
{
fn from(s: S) -> Self {
let s: String = s.into();
match s.as_str() {
"activitypub" => Self::ActivityPub,
"atproto" => Self::ATProto,
"rss" => Self::Rss,
"web" => Self::Web,
_ => Self::Custom(s),
}
}
}