twilight_model/guild/auto_moderation/
event_type.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
5#[serde(from = "u8", into = "u8")]
6pub enum AutoModerationEventType {
7 MessageSend,
9 MemberUpdate,
11 Unknown(u8),
13}
14
15impl From<u8> for AutoModerationEventType {
16 fn from(value: u8) -> Self {
17 match value {
18 1 => Self::MessageSend,
19 2 => Self::MemberUpdate,
20 _ => Self::Unknown(value),
21 }
22 }
23}
24
25impl From<AutoModerationEventType> for u8 {
26 fn from(value: AutoModerationEventType) -> Self {
27 match value {
28 AutoModerationEventType::MessageSend => 1,
29 AutoModerationEventType::MemberUpdate => 2,
30 AutoModerationEventType::Unknown(unknown) => unknown,
31 }
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::AutoModerationEventType;
38 use serde::{Deserialize, Serialize};
39 use static_assertions::assert_impl_all;
40 use std::{fmt::Debug, hash::Hash};
41
42 assert_impl_all!(
43 AutoModerationEventType: Clone,
44 Copy,
45 Debug,
46 Deserialize<'static>,
47 Eq,
48 Hash,
49 PartialEq,
50 Send,
51 Serialize,
52 Sync,
53 );
54
55 #[test]
56 fn values() {
57 assert_eq!(1, u8::from(AutoModerationEventType::MessageSend));
58 assert_eq!(2, u8::from(AutoModerationEventType::MemberUpdate));
59 assert_eq!(250, u8::from(AutoModerationEventType::Unknown(250)));
60 }
61}