twilight_model/gateway/presence/
activity_type.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
4#[non_exhaustive]
5#[serde(from = "u8", into = "u8")]
6pub enum ActivityType {
7 Playing,
8 Streaming,
9 Listening,
10 Watching,
11 Custom,
12 Competing,
13 Unknown(u8),
14}
15
16impl From<u8> for ActivityType {
17 fn from(value: u8) -> Self {
18 match value {
19 0 => ActivityType::Playing,
20 1 => ActivityType::Streaming,
21 2 => ActivityType::Listening,
22 3 => ActivityType::Watching,
23 4 => ActivityType::Custom,
24 5 => ActivityType::Competing,
25 unknown => ActivityType::Unknown(unknown),
26 }
27 }
28}
29
30impl From<ActivityType> for u8 {
31 fn from(value: ActivityType) -> Self {
32 match value {
33 ActivityType::Playing => 0,
34 ActivityType::Streaming => 1,
35 ActivityType::Listening => 2,
36 ActivityType::Watching => 3,
37 ActivityType::Custom => 4,
38 ActivityType::Competing => 5,
39 ActivityType::Unknown(unknown) => unknown,
40 }
41 }
42}
43
44impl Default for ActivityType {
45 fn default() -> Self {
46 Self::Playing
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::ActivityType;
53 use serde_test::Token;
54
55 #[test]
56 fn default() {
57 assert_eq!(ActivityType::Playing, ActivityType::default());
58 }
59
60 #[test]
61 fn variants() {
62 serde_test::assert_tokens(&ActivityType::Playing, &[Token::U8(0)]);
63 serde_test::assert_tokens(&ActivityType::Streaming, &[Token::U8(1)]);
64 serde_test::assert_tokens(&ActivityType::Listening, &[Token::U8(2)]);
65 serde_test::assert_tokens(&ActivityType::Watching, &[Token::U8(3)]);
66 serde_test::assert_tokens(&ActivityType::Custom, &[Token::U8(4)]);
67 serde_test::assert_tokens(&ActivityType::Competing, &[Token::U8(5)]);
68 serde_test::assert_tokens(&ActivityType::Unknown(99), &[Token::U8(99)]);
69 }
70}