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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter, Result as FmtResult};

/// Unique ID denoting a sticker.
///
/// # serde
///
/// Like all of the IDs in the primary [`crate::id`] crate, these
/// IDs support deserializing from both integers and strings and serialize into
/// strings.
#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct StickerId(#[serde(with = "crate::id::string")] pub u64);

impl Display for StickerId {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        Display::fmt(&self.0, f)
    }
}

/// Unique ID denoting a sticker pack.
///
/// # serde
///
/// Like all of the IDs in the primary [`crate::id`] crate, these
/// IDs support deserializing from both integers and strings and serialize into
/// strings.
#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct StickerPackId(#[serde(with = "crate::id::string")] pub u64);

impl Display for StickerPackId {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        Display::fmt(&self.0, f)
    }
}

#[cfg(test)]
mod tests {
    use super::{StickerId, StickerPackId};
    use serde_test::Token;

    #[test]
    fn test_id_deser() {
        serde_test::assert_tokens(
            &StickerId(114_941_315_417_899_012),
            &[
                Token::NewtypeStruct { name: "StickerId" },
                Token::Str("114941315417899012"),
            ],
        );
        serde_test::assert_de_tokens(
            &StickerId(114_941_315_417_899_012),
            &[
                Token::NewtypeStruct { name: "StickerId" },
                Token::U64(114_941_315_417_899_012),
            ],
        );
        serde_test::assert_tokens(
            &StickerPackId(114_941_315_417_899_012),
            &[
                Token::NewtypeStruct {
                    name: "StickerPackId",
                },
                Token::Str("114941315417899012"),
            ],
        );
        serde_test::assert_de_tokens(
            &StickerPackId(114_941_315_417_899_012),
            &[
                Token::NewtypeStruct {
                    name: "StickerPackId",
                },
                Token::U64(114_941_315_417_899_012),
            ],
        );
    }
}