Skip to main content

twilight_http/request/
get_gateway_authed.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::gateway::connection_info::BotConnectionInfo;
11
12/// Get information about the gateway, authenticated as a bot user.
13///
14/// Returns additional information: the recommended number of shards to use, and information on
15/// the current session start limit.
16#[must_use = "requests must be configured and executed"]
17pub struct GetGatewayAuthed<'a> {
18    http: &'a Client,
19}
20
21impl<'a> GetGatewayAuthed<'a> {
22    pub(crate) const fn new(http: &'a Client) -> Self {
23        Self { http }
24    }
25}
26
27#[cfg(not(target_os = "wasi"))]
28impl IntoFuture for GetGatewayAuthed<'_> {
29    type Output = Result<Response<BotConnectionInfo>, Error>;
30
31    type IntoFuture = ResponseFuture<BotConnectionInfo>;
32
33    fn into_future(self) -> Self::IntoFuture {
34        let http = self.http;
35
36        match self.try_into_request() {
37            Ok(request) => http.request(request),
38            Err(source) => ResponseFuture::error(source),
39        }
40    }
41}
42
43impl TryIntoRequest for GetGatewayAuthed<'_> {
44    fn try_into_request(self) -> Result<Request, Error> {
45        Ok(Request::from_route(&Route::GetGatewayBot))
46    }
47}