twilight_model/gateway/session_start_limit.rs
1use serde::{Deserialize, Serialize};
2
3/// Current gateway session utilization status.
4///
5/// Most bots have a `max_concurrency` of 1 and a `total` of 1000, but this is
6/// increased for those with large bot sharding (in more than 150,000 guilds).
7/// See [Discord Docs/Sharding for Large Bots].
8///
9/// [Discord Docs/Sharding for Large Bots]: https://discord.com/developers/docs/topics/gateway#sharding-for-large-bots
10#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
11pub struct SessionStartLimit {
12 /// Maximum number of session that may be started concurrently.
13 pub max_concurrency: u16,
14 /// Number of remaining sessions for a given time period.
15 pub remaining: u32,
16 /// Milliseconds until `remaining` resets back to `total`.
17 pub reset_after: u64,
18 /// Total number of sessions that can be started within the given time
19 /// period.
20 pub total: u32,
21}
22
23#[cfg(test)]
24mod tests {
25 use super::SessionStartLimit;
26 use serde_test::Token;
27
28 #[test]
29 fn connection_info() {
30 let value = SessionStartLimit {
31 max_concurrency: 16,
32 remaining: 998,
33 reset_after: 84_686_789,
34 total: 1_000,
35 };
36
37 serde_test::assert_tokens(
38 &value,
39 &[
40 Token::Struct {
41 name: "SessionStartLimit",
42 len: 4,
43 },
44 Token::Str("max_concurrency"),
45 Token::U16(16),
46 Token::Str("remaining"),
47 Token::U32(998),
48 Token::Str("reset_after"),
49 Token::U64(84_686_789),
50 Token::Str("total"),
51 Token::U32(1_000),
52 Token::StructEnd,
53 ],
54 );
55 }
56}