twilight_model/channel/stage_instance/
mod.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
68
69
mod privacy_level;

pub use self::privacy_level::PrivacyLevel;

use crate::id::{
    marker::{ChannelMarker, GuildMarker, ScheduledEventMarker, StageMarker},
    Id,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct StageInstance {
    pub channel_id: Id<ChannelMarker>,
    pub guild_id: Id<GuildMarker>,
    /// The id of the [`GuildScheduledEvent`].
    ///
    /// [`GuildScheduledEvent`]: crate::guild::scheduled_event::GuildScheduledEvent
    pub guild_scheduled_event_id: Option<Id<ScheduledEventMarker>>,
    pub id: Id<StageMarker>,
    pub privacy_level: PrivacyLevel,
    pub topic: String,
}

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

    #[test]
    fn stage_instance() {
        let value = StageInstance {
            channel_id: Id::new(100),
            guild_id: Id::new(200),
            guild_scheduled_event_id: Some(Id::new(300)),
            id: Id::new(400),
            privacy_level: PrivacyLevel::GuildOnly,
            topic: "a topic".into(),
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "StageInstance",
                    len: 6,
                },
                Token::Str("channel_id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("100"),
                Token::Str("guild_id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("200"),
                Token::Str("guild_scheduled_event_id"),
                Token::Some,
                Token::NewtypeStruct { name: "Id" },
                Token::Str("300"),
                Token::Str("id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("400"),
                Token::Str("privacy_level"),
                Token::U8(2),
                Token::Str("topic"),
                Token::Str("a topic"),
                Token::StructEnd,
            ],
        );
    }
}