pub fn bucket(
bucket_id: u16,
buckets: u16,
shards: u32,
) -> impl DoubleEndedIterator<Item = ShardId> + ExactSizeIteratorExpand description
Creates an iterator of a single bucket’s worth of shard identifiers.
Each bucket holds a consecutive range of identifiers and all identifiers
share the same total value.
§Strategy
Shards may be bucketed per-thread for a thread-per-core architecture and/or per-machine for horizontal scaling.
§Examples
Create 1 bucket with the recommended shard count:
use std::env;
use twilight_http::Client;
let http = Client::new(env::var("TOKEN")?);
let info = http.gateway().authed().await?.model().await?;
let shards = twilight_gateway::bucket(0, 1, info.shards);
assert_eq!(shards.len(), info.shards as usize);Create 2 buckets with 25 identifiers:
let bucket_1 = twilight_gateway::bucket(0, 2, 25);
let bucket_2 = twilight_gateway::bucket(1, 2, 25);
assert_eq!(bucket_1.len(), 13);
assert_eq!(bucket_2.len(), 12);§Panics
Panics if the bucket id is greater than or equal to the total number of buckets.