pub struct Session { /* private fields */ }
Expand description
Gateway session information for a shard’s active connection.
A session is a stateful identifier on Discord’s end for running a shard. It is used for maintaining an authenticated Websocket connection based on an identifier. While a session is only connected to one shard, one shard can have more than one session: if a shard shuts down its connection and starts a new session, then the previous session will be kept alive for a short time.
§Reusing sessions
Sessions are able to be reused across connections to Discord. If an
application’s process needs to be restarted, then this session
information—which can be (de)serialized via serde—can be stored, the
application restarted, and then used again via ConfigBuilder::session
.
If the delay between disconnecting from the gateway and reconnecting isn’t too long and Discord hasn’t invalidated the session, then the session will be reused by Discord. As a result, any events that were “missed” while restarting and reconnecting will be played back, meaning the application won’t have missed any events. If the delay has been too long, then a new session will be initialized, resulting in those events being missed.
Implementations§
Source§impl Session
impl Session
Sourcepub fn new(sequence: u64, session_id: String) -> Self
pub fn new(sequence: u64, session_id: String) -> Self
Create new configuration for resuming a gateway session.
Can be provided to ConfigBuilder::session
.
Sourcepub const fn id(&self) -> &str
pub const fn id(&self) -> &str
ID of the session being resumed.
The ID of the session is different from the ID of the shard; shards are identified by an index, and when authenticated with the gateway the shard is given a unique identifier for the gateway session.
Session IDs are obtained by shards via sending an Identify
command
with the shard’s authentication details, and in return the session ID is
provided via the Ready
event.
Sourcepub const fn sequence(&self) -> u64
pub const fn sequence(&self) -> u64
Current sequence of the connection.
Number of the events that have been received during this session. A larger number typically correlates that the shard has been connected with this session for a longer time, while a smaller number typically correlates to meaning that it’s been connected with this session for a shorter duration of time.
As a shard is connected to the gateway and receives events this sequence will be updated in real time when obtaining the session of a shard.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Session
impl<'de> Deserialize<'de> for Session
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Session
impl StructuralPartialEq for Session
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.