twilight_model/oauth/
application_integration_type.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use serde::{Deserialize, Serialize};

use super::InstallParams;

#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
#[serde(from = "u8", into = "u8")]
pub enum ApplicationIntegrationType {
    GuildInstall,
    UserInstall,
    /// Variant value is unknown to the library.
    Unknown(u8),
}

impl ApplicationIntegrationType {
    pub const fn kind(self) -> &'static str {
        match self {
            Self::GuildInstall => "GUILD_INSTALL",
            Self::UserInstall => "USER_INSTALL",
            Self::Unknown(_) => "Unknown",
        }
    }
}

impl From<u8> for ApplicationIntegrationType {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::GuildInstall,
            1 => Self::UserInstall,
            unknown => Self::Unknown(unknown),
        }
    }
}

impl From<ApplicationIntegrationType> for u8 {
    fn from(value: ApplicationIntegrationType) -> Self {
        match value {
            ApplicationIntegrationType::GuildInstall => 0,
            ApplicationIntegrationType::UserInstall => 1,
            ApplicationIntegrationType::Unknown(unknown) => unknown,
        }
    }
}

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct ApplicationIntegrationMap<Guild, User = Guild> {
    #[serde(rename = "0")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub guild: Option<Guild>,
    #[serde(rename = "1")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user: Option<User>,
}

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct ApplicationIntegrationTypeConfig {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub oauth2_install_params: Option<InstallParams>,
}