1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("../README.md")]
3#![warn(
4 clippy::missing_const_for_fn,
5 clippy::missing_docs_in_private_items,
6 clippy::pedantic,
7 missing_docs,
8 unsafe_code
9)]
10#![allow(
11 clippy::module_name_repetitions,
12 clippy::must_use_candidate,
13 clippy::unnecessary_wraps
14)]
15
16pub mod error;
17
18mod channel;
19mod command;
20#[cfg(any(feature = "zlib", feature = "zstd"))]
21mod compression;
22mod config;
23mod event;
24mod json;
25mod latency;
26mod message;
27mod ratelimiter;
28mod session;
29mod shard;
30mod stream;
31
32pub use self::{
33 channel::MessageSender,
34 command::Command,
35 config::{Config, ConfigBuilder},
36 event::EventTypeFlags,
37 json::parse,
38 latency::Latency,
39 message::Message,
40 ratelimiter::CommandRatelimiter,
41 session::Session,
42 shard::{Shard, ShardState},
43 stream::StreamExt,
44};
45pub use twilight_model::gateway::{CloseFrame, Intents, ShardId};
46
47#[doc(no_inline)]
48pub use twilight_gateway_queue as queue;
49#[doc(no_inline)]
50pub use twilight_model::gateway::event::{Event, EventType};
51
52pub const API_VERSION: u8 = 10;
54
55#[inline]
99#[track_caller]
100pub fn bucket(
101 bucket_id: u16,
102 buckets: u16,
103 shards: u32,
104) -> impl DoubleEndedIterator<Item = ShardId> + ExactSizeIterator {
105 let bucket_id = u32::from(bucket_id);
106 let buckets = u32::from(buckets);
107 assert!(bucket_id < buckets, "bucket_id must be less than buckets");
108
109 let (q, r) = (shards / buckets, shards % buckets);
110
111 let len = q + u32::from(bucket_id < r);
112 let start = bucket_id * q + r.min(bucket_id);
113
114 if shards < start + len {
116 std::process::abort();
117 }
118 (start..start + len).map(move |id| ShardId::new(id, shards))
119}