twilight_model/channel/message/sticker/
message.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
60
61
62
63
64
65
66
67
use super::StickerFormatType;
use crate::id::{marker::StickerMarker, Id};
use serde::{Deserialize, Serialize};

/// Smallest amount of data required to render a [`Sticker`].
///
/// [`Sticker`]: super::Sticker
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct MessageSticker {
    /// Format type.
    pub format_type: StickerFormatType,
    /// ID of the sticker.
    pub id: Id<StickerMarker>,
    /// Name of the sticker.
    pub name: String,
}

#[cfg(test)]
mod tests {
    use super::{MessageSticker, StickerFormatType};
    use crate::id::Id;
    use serde::{Deserialize, Serialize};
    use serde_test::Token;
    use static_assertions::{assert_fields, assert_impl_all};
    use std::{fmt::Debug, hash::Hash};

    assert_fields!(MessageSticker: format_type, id, name);

    assert_impl_all!(
        MessageSticker: Clone,
        Debug,
        Deserialize<'static>,
        Eq,
        Hash,
        PartialEq,
        Send,
        Serialize,
        Sync,
    );

    #[test]
    fn full() {
        let value = MessageSticker {
            format_type: StickerFormatType::Lottie,
            id: Id::new(1),
            name: "sticker".into(),
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "MessageSticker",
                    len: 3,
                },
                Token::Str("format_type"),
                Token::U8(StickerFormatType::Lottie.into()),
                Token::Str("id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("1"),
                Token::Str("name"),
                Token::Str("sticker"),
                Token::StructEnd,
            ],
        );
    }
}