use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum GenerateLinkIntent {
SSO,
Dsync,
AuditLogs,
LogStreams,
DomainVerification,
CertificateRenewal,
BringYourOwnKey,
Unknown(String),
}
impl GenerateLinkIntent {
#[allow(deprecated)]
pub fn as_str(&self) -> &str {
match self {
Self::SSO => "sso",
Self::Dsync => "dsync",
Self::AuditLogs => "audit_logs",
Self::LogStreams => "log_streams",
Self::DomainVerification => "domain_verification",
Self::CertificateRenewal => "certificate_renewal",
Self::BringYourOwnKey => "bring_your_own_key",
Self::Unknown(s) => s.as_str(),
}
}
}
impl fmt::Display for GenerateLinkIntent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl AsRef<str> for GenerateLinkIntent {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl FromStr for GenerateLinkIntent {
type Err = std::convert::Infallible;
#[allow(deprecated)]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"sso" => Self::SSO,
"dsync" => Self::Dsync,
"audit_logs" => Self::AuditLogs,
"log_streams" => Self::LogStreams,
"domain_verification" => Self::DomainVerification,
"certificate_renewal" => Self::CertificateRenewal,
"bring_your_own_key" => Self::BringYourOwnKey,
other => Self::Unknown(other.to_string()),
})
}
}
impl From<String> for GenerateLinkIntent {
fn from(s: String) -> Self {
match Self::from_str(&s) {
Ok(Self::Unknown(_)) => Self::Unknown(s),
Ok(other) => other,
}
}
}
impl From<&str> for GenerateLinkIntent {
fn from(s: &str) -> Self {
Self::from_str(s).unwrap_or_else(|_| Self::Unknown(s.to_string()))
}
}
impl Serialize for GenerateLinkIntent {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(self.as_str())
}
}
impl<'de> Deserialize<'de> for GenerateLinkIntent {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}