twilight_model/channel/message/sticker/
kind.rs

1use serde::{Deserialize, Serialize};
2
3/// Type of a [`Sticker`].
4///
5/// [`Sticker`]: super::Sticker
6#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
7#[non_exhaustive]
8#[serde(from = "u8", into = "u8")]
9pub enum StickerType {
10    /// Official sticker in a pack.
11    ///
12    /// Part of nitro or in a removed purchasable pack.
13    Standard,
14    /// Sticker uploaded to a boosted guild for the guild's members.
15    Guild,
16    /// Variant value is unknown to the library.
17    Unknown(u8),
18}
19
20impl From<u8> for StickerType {
21    fn from(value: u8) -> Self {
22        match value {
23            1 => StickerType::Standard,
24            2 => StickerType::Guild,
25            unknown => StickerType::Unknown(unknown),
26        }
27    }
28}
29
30impl From<StickerType> for u8 {
31    fn from(value: StickerType) -> Self {
32        match value {
33            StickerType::Standard => 1,
34            StickerType::Guild => 2,
35            StickerType::Unknown(unknown) => unknown,
36        }
37    }
38}
39
40#[cfg(test)]
41mod tests {
42    use super::StickerType;
43    use serde_test::Token;
44
45    #[test]
46    fn variants() {
47        serde_test::assert_tokens(&StickerType::Standard, &[Token::U8(1)]);
48        serde_test::assert_tokens(&StickerType::Guild, &[Token::U8(2)]);
49        serde_test::assert_tokens(&StickerType::Unknown(99), &[Token::U8(99)]);
50    }
51
52    #[test]
53    fn conversions() {
54        assert_eq!(StickerType::from(1), StickerType::Standard);
55        assert_eq!(StickerType::from(2), StickerType::Guild);
56        assert_eq!(StickerType::from(99), StickerType::Unknown(99));
57    }
58}