use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum AuditLogConfigurationLogStreamState {
Active,
Inactive,
Error,
Invalid,
Unknown(String),
}
impl AuditLogConfigurationLogStreamState {
#[allow(deprecated)]
pub fn as_str(&self) -> &str {
match self {
Self::Active => "active",
Self::Inactive => "inactive",
Self::Error => "error",
Self::Invalid => "invalid",
Self::Unknown(s) => s.as_str(),
}
}
}
impl fmt::Display for AuditLogConfigurationLogStreamState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl AsRef<str> for AuditLogConfigurationLogStreamState {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl FromStr for AuditLogConfigurationLogStreamState {
type Err = std::convert::Infallible;
#[allow(deprecated)]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"active" => Self::Active,
"inactive" => Self::Inactive,
"error" => Self::Error,
"invalid" => Self::Invalid,
other => Self::Unknown(other.to_string()),
})
}
}
impl From<String> for AuditLogConfigurationLogStreamState {
fn from(s: String) -> Self {
match Self::from_str(&s) {
Ok(Self::Unknown(_)) => Self::Unknown(s),
Ok(other) => other,
}
}
}
impl From<&str> for AuditLogConfigurationLogStreamState {
fn from(s: &str) -> Self {
Self::from_str(s).unwrap_or_else(|_| Self::Unknown(s.to_string()))
}
}
impl Serialize for AuditLogConfigurationLogStreamState {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(self.as_str())
}
}
impl<'de> Deserialize<'de> for AuditLogConfigurationLogStreamState {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}