pub fn create_range<F: Fn(ShardId, ConfigBuilder) -> Config>(
range: impl RangeBounds<u64>,
total: u64,
config: Config,
per_shard_config: F
) -> impl Iterator<Item = Shard>
Expand description

Create a range of shards.

Passing a primary config is required. Further customization of this config may be performed in the callback.

Examples

Start 10 out of 10 shards and collect them into a map:

use std::{collections::HashMap, env, sync::Arc};
use twilight_gateway::{queue::LocalQueue, stream, Config, Intents};

let token = env::var("DISCORD_TOKEN")?;

let config = Config::new(token.clone(), Intents::GUILDS);
let shards = stream::create_range(0..10, 10, config, |_, builder| builder.build())
    .map(|shard| (shard.id().number(), shard))
    .collect::<HashMap<_, _>>();

assert_eq!(shards.len(), 10);

Panics

Panics if start >= total or if end > total, where start and end refer to range’s start and end.

Panics if loading TLS certificates fails.