pub struct Shard { /* private fields */ }Expand description
A Discord Gateway shard.
Handles WebSocket connection, heartbeating, event dispatch, and automatic reconnection with session resumption.
Implementations§
Source§impl Shard
impl Shard
Sourcepub fn new(shard_id: u16, total_shards: u16, config: ShardConfig) -> Self
pub fn new(shard_id: u16, total_shards: u16, config: ShardConfig) -> Self
Create a new shard.
§Arguments
shard_id- This shard’s ID (0-indexed).total_shards- Total number of shards.config- Shard configuration.
Sourcepub fn with_rate_limiter(
shard_id: u16,
total_shards: u16,
config: ShardConfig,
rate_limiter: Arc<IdentifyRateLimiter>,
) -> Self
pub fn with_rate_limiter( shard_id: u16, total_shards: u16, config: ShardConfig, rate_limiter: Arc<IdentifyRateLimiter>, ) -> Self
Create a new shard with a shared rate limiter.
Sourcepub fn total_shards(&self) -> u16
pub fn total_shards(&self) -> u16
Get the total number of shards.
Sourcepub fn state(&self) -> ShardState
pub fn state(&self) -> ShardState
Get the current shard state.
Sourcepub fn send_payload<T: Serialize>(
&self,
payload: &T,
) -> Result<(), GatewayError>
pub fn send_payload<T: Serialize>( &self, payload: &T, ) -> Result<(), GatewayError>
Send a raw payload to the gateway.
This is useful for sending voice state updates (Op 4) or presence updates (Op 3).
Accepts any type that implements serde::Serialize.
Auto Trait Implementations§
impl !Freeze for Shard
impl !RefUnwindSafe for Shard
impl Send for Shard
impl Sync for Shard
impl Unpin for Shard
impl !UnwindSafe for Shard
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
Mutably borrows from an owned value. Read more