twilight_model/gateway/connection_info/
bot_connection_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
57
58
59
60
61
62
63
use crate::gateway::SessionStartLimit;
use serde::{Deserialize, Serialize};

/// Gateway information containing the recommended shard count and session
/// availability.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct BotConnectionInfo {
    /// Current session availability and session connection concurrency limits.
    pub session_start_limit: SessionStartLimit,
    /// Recommended shard count to use.
    pub shards: u32,
    /// URL to the gateway.
    pub url: String,
}

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

    #[test]
    fn connection_info() {
        let value = BotConnectionInfo {
            session_start_limit: SessionStartLimit {
                max_concurrency: 16,
                remaining: 998,
                reset_after: 84_686_789,
                total: 1000,
            },
            shards: 3,
            url: "wss://gateway.discord.gg".to_owned(),
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "BotConnectionInfo",
                    len: 3,
                },
                Token::Str("session_start_limit"),
                Token::Struct {
                    name: "SessionStartLimit",
                    len: 4,
                },
                Token::Str("max_concurrency"),
                Token::U16(16),
                Token::Str("remaining"),
                Token::U32(998),
                Token::Str("reset_after"),
                Token::U64(84_686_789),
                Token::Str("total"),
                Token::U32(1000),
                Token::StructEnd,
                Token::Str("shards"),
                Token::U32(3),
                Token::Str("url"),
                Token::Str("wss://gateway.discord.gg"),
                Token::StructEnd,
            ],
        );
    }
}