twilight_model/guild/auto_moderation/
trigger_type.rsuse serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(from = "u8", into = "u8")]
pub enum AutoModerationTriggerType {
Keyword,
Spam,
KeywordPreset,
MentionSpam,
MemberProfile,
Unknown(u8),
}
impl From<u8> for AutoModerationTriggerType {
fn from(value: u8) -> Self {
match value {
1 => Self::Keyword,
3 => Self::Spam,
4 => Self::KeywordPreset,
5 => Self::MentionSpam,
6 => Self::MemberProfile,
_ => Self::Unknown(value),
}
}
}
impl From<AutoModerationTriggerType> for u8 {
fn from(value: AutoModerationTriggerType) -> Self {
match value {
AutoModerationTriggerType::Keyword => 1,
AutoModerationTriggerType::Spam => 3,
AutoModerationTriggerType::KeywordPreset => 4,
AutoModerationTriggerType::MentionSpam => 5,
AutoModerationTriggerType::MemberProfile => 6,
AutoModerationTriggerType::Unknown(unknown) => unknown,
}
}
}
#[cfg(test)]
mod tests {
use super::AutoModerationTriggerType;
use serde::{Deserialize, Serialize};
use static_assertions::assert_impl_all;
use std::{fmt::Debug, hash::Hash};
assert_impl_all!(
AutoModerationTriggerType: Clone,
Copy,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Send,
Serialize,
Sync,
);
#[test]
fn values() {
assert_eq!(1, u8::from(AutoModerationTriggerType::Keyword));
assert_eq!(3, u8::from(AutoModerationTriggerType::Spam));
assert_eq!(4, u8::from(AutoModerationTriggerType::KeywordPreset));
assert_eq!(5, u8::from(AutoModerationTriggerType::MentionSpam));
assert_eq!(6, u8::from(AutoModerationTriggerType::MemberProfile));
assert_eq!(250, u8::from(AutoModerationTriggerType::Unknown(250)));
}
}