twilight_model/guild/
info.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
use crate::{
    guild::Permissions,
    id::{marker::GuildMarker, Id},
    util::image_hash::ImageHash,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct GuildInfo {
    pub icon: Option<ImageHash>,
    pub id: Id<GuildMarker>,
    pub name: String,
    pub owner: bool,
    pub permissions: Permissions,
}

#[cfg(test)]
mod tests {
    use super::{GuildInfo, Permissions};
    use crate::{id::Id, test::image_hash};
    use serde_test::Token;

    #[test]
    fn guild_info() {
        let value = GuildInfo {
            icon: Some(image_hash::ICON),
            id: Id::new(1),
            name: "guild name".to_owned(),
            owner: false,
            permissions: Permissions::MANAGE_CHANNELS,
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "GuildInfo",
                    len: 5,
                },
                Token::Str("icon"),
                Token::Some,
                Token::Str(image_hash::ICON_INPUT),
                Token::Str("id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("1"),
                Token::Str("name"),
                Token::Str("guild name"),
                Token::Str("owner"),
                Token::Bool(false),
                Token::Str("permissions"),
                Token::Str("16"),
                Token::StructEnd,
            ],
        );
    }
}