pub struct ShardId { /* private fields */ }Expand description
Identifies a shard: its number and the total number of shards.
Discord sends this as a two-element array, [shard_id, num_shards]. A guild belongs to shard
(guild_id >> 22) % total — see ShardId::for_guild.
§Invariants
total is at least 1 and number < total.
discord.js counterpart: shard / shardCount client options and ShardClientUtil.
§Examples
use djs_model::{gateway::ShardId, id::GuildId};
let shard = ShardId::new(0, 1);
assert_eq!(shard.to_string(), "[0, 1]");
let guild = GuildId::new(175_928_847_299_117_063);
assert_eq!(ShardId::for_guild(guild, 4).number(), 0);Implementations§
Source§impl ShardId
impl ShardId
Sourcepub const fn new(number: u32, total: u32) -> Self
pub const fn new(number: u32, total: u32) -> Self
Creates a shard ID.
discord.js counterpart: ShardClientUtil.shardIdForGuildId’s numbers.
§Panics
Panics if total is 0 or number >= total.
Sourcepub const fn new_checked(number: u32, total: u32) -> Option<Self>
pub const fn new_checked(number: u32, total: u32) -> Option<Self>
Creates a shard ID, returning None if total is 0 or number >= total.
discord.js counterpart: none (discord.js keeps shard IDs as numbers).
Sourcepub const fn for_guild(guild: GuildId, total: u32) -> Self
pub const fn for_guild(guild: GuildId, total: u32) -> Self
Returns the shard that handles events of guild when there are total shards.
Uses Discord’s sharding formula, shard_id = (guild_id >> 22) % num_shards.
§Panics
Panics if total is 0.
Trait Implementations§
impl Copy for ShardId
Source§impl<'de> Deserialize<'de> for ShardId
impl<'de> Deserialize<'de> for ShardId
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for ShardId
Source§impl Ord for ShardId
impl Ord for ShardId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for ShardId
impl PartialOrd for ShardId
impl StructuralPartialEq for ShardId
Auto Trait Implementations§
impl Freeze for ShardId
impl RefUnwindSafe for ShardId
impl Send for ShardId
impl Sync for ShardId
impl Unpin for ShardId
impl UnsafeUnpin for ShardId
impl UnwindSafe for ShardId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more