twilight_model/guild/
integration_type.rs#![allow(deprecated)]
use std::borrow::Cow;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
#[serde(from = "String", into = "Cow<'static, str>")]
pub enum GuildIntegrationType {
Discord,
Twitch,
YouTube,
GuildSubscription,
Unknown(String),
}
impl From<GuildIntegrationType> for Cow<'static, str> {
fn from(value: GuildIntegrationType) -> Self {
match value {
GuildIntegrationType::Discord => "discord".into(),
GuildIntegrationType::Twitch => "twitch".into(),
GuildIntegrationType::YouTube => "youtube".into(),
GuildIntegrationType::GuildSubscription => "guild_subscription".into(),
GuildIntegrationType::Unknown(unknown) => unknown.into(),
}
}
}
impl From<String> for GuildIntegrationType {
fn from(value: String) -> Self {
match value.as_str() {
"discord" => Self::Discord,
"twitch" => Self::Twitch,
"youtube" => Self::YouTube,
"guild_subscription" => Self::GuildSubscription,
_ => Self::Unknown(value),
}
}
}
#[cfg(test)]
mod tests {
use super::GuildIntegrationType;
use serde_test::Token;
#[test]
fn variants() {
const MAP: &[(GuildIntegrationType, &str)] = &[
(GuildIntegrationType::Discord, "discord"),
(GuildIntegrationType::Twitch, "twitch"),
(GuildIntegrationType::YouTube, "youtube"),
(
GuildIntegrationType::GuildSubscription,
"guild_subscription",
),
];
for (integration_type, value) in MAP {
serde_test::assert_tokens(integration_type, &[Token::Str(value)]);
}
}
}