Struct Shard

Source
pub struct Shard {
    pub token: String,
    pub info: [usize; 2],
    pub presence: ClientPresence,
    pub session_id: Option<String>,
    pub interval: Option<u64>,
    pub sender: Arc<Mutex<UnboundedSender<Message>>>,
    pub stream: Arc<Mutex<Option<SplitStream<WebSocketStream<Stream<TcpStream, TlsStream<TcpStream>>>>>>>,
    pub heartbeat: Arc<Mutex<Heartbeat>>,
    /* private fields */
}
Expand description

A Spectacles Gateway shard.

Fields§

§token: String

The bot token that this shard will use.

§info: [usize; 2]

The shard’s info. Includes the shard’s ID and the total amount of shards.

§presence: ClientPresence

The currently active presence for this shard.

§session_id: Option<String>

The session ID of this shard, if applicable.

§interval: Option<u64>

The interval at which a heartbeat is made.

§sender: Arc<Mutex<UnboundedSender<Message>>>

The channel which is used to send websocket messages.

§stream: Arc<Mutex<Option<SplitStream<WebSocketStream<Stream<TcpStream, TlsStream<TcpStream>>>>>>>

The shard’s message stream, which is used to receive messages.

§heartbeat: Arc<Mutex<Heartbeat>>

This shard’s current heartbeat.

Implementations§

Source§

impl Shard

Source

pub fn new( token: String, info: [usize; 2], ws_uri: String, ) -> impl Future<Item = Shard, Error = Error>

Creates a new Discord Shard, with the provided token.

Source

pub fn fulfill_gateway(&mut self, packet: ReceivePacket) -> Result<ShardAction>

Source

pub fn identify(&mut self) -> Result<()>

Identifies a shard with Discord.

Source

pub fn autoreconnect( &mut self, ) -> Box<dyn Future<Item = (), Error = Error> + Send>

Attempts to automatically reconnect the shard to Discord.

Source

pub fn reconnect(&mut self) -> impl Future<Item = (), Error = Error> + Send

Makes a request to reconnect the shard.

Source

pub fn resume(&mut self) -> impl Future<Item = (), Error = Error> + Send

Resumes a shard’s past session.

Source

pub fn resolve_packet(&self, mess: &WebsocketMessage) -> Result<ReceivePacket>

Resolves a Websocket message into a ReceivePacket struct.

Source

pub fn send_payload<T: SendablePacket>(&self, payload: T) -> Result<()>

Sends a payload to the Discord Gateway.

Source

pub fn change_status(&mut self, status: Status) -> Result<()>

Change the status of the current shard.

Source

pub fn change_activity(&mut self, activity: ClientActivity) -> Result<()>

Change the activity of the current shard.

Source

pub fn change_presence(&mut self, presence: ClientPresence) -> Result<()>

Change the presence of the current shard.

Trait Implementations§

Source§

impl Clone for Shard

Source§

fn clone(&self) -> Shard

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Err = <U as TryFrom<T>>::Err

Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Err>

Source§

impl<T> Erased for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,