twilight_model/application/interaction/
context_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 InteractionContextType {
7 Guild,
9 BotDm,
11 PrivateChannel,
14 Unknown(u8),
16}
17
18impl InteractionContextType {
19 pub const fn kind(self) -> &'static str {
20 match self {
21 Self::Guild => "GUILD",
22 Self::BotDm => "BOT_DM",
23 Self::PrivateChannel => "PRIVATE_CHANNEL",
24 Self::Unknown(_) => "Unknown",
25 }
26 }
27}
28
29impl From<u8> for InteractionContextType {
30 fn from(value: u8) -> Self {
31 match value {
32 0 => Self::Guild,
33 1 => Self::BotDm,
34 2 => Self::PrivateChannel,
35 unknown => Self::Unknown(unknown),
36 }
37 }
38}
39
40impl From<InteractionContextType> for u8 {
41 fn from(value: InteractionContextType) -> Self {
42 match value {
43 InteractionContextType::Guild => 0,
44 InteractionContextType::BotDm => 1,
45 InteractionContextType::PrivateChannel => 2,
46 InteractionContextType::Unknown(unknown) => unknown,
47 }
48 }
49}