Skip to main content

twilight_http/request/application/command/
get_global_commands.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture, marker::ListBody};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::{
11    application::command::Command,
12    id::{Id, marker::ApplicationMarker},
13};
14
15/// Retrieve all global commands for an application.
16#[must_use = "requests must be configured and executed"]
17pub struct GetGlobalCommands<'a> {
18    application_id: Id<ApplicationMarker>,
19    http: &'a Client,
20    with_localizations: Option<bool>,
21}
22
23impl<'a> GetGlobalCommands<'a> {
24    pub(crate) const fn new(http: &'a Client, application_id: Id<ApplicationMarker>) -> Self {
25        Self {
26            application_id,
27            http,
28            with_localizations: None,
29        }
30    }
31
32    /// Whether to include full localization dictionaries in the response.
33    ///
34    /// Defaults to [`false`].
35    pub const fn with_localizations(mut self, with_localizations: bool) -> Self {
36        self.with_localizations = Some(with_localizations);
37
38        self
39    }
40}
41
42#[cfg(not(target_os = "wasi"))]
43impl IntoFuture for GetGlobalCommands<'_> {
44    type Output = Result<Response<ListBody<Command>>, Error>;
45
46    type IntoFuture = ResponseFuture<ListBody<Command>>;
47
48    fn into_future(self) -> Self::IntoFuture {
49        let http = self.http;
50
51        match self.try_into_request() {
52            Ok(request) => http.request(request),
53            Err(source) => ResponseFuture::error(source),
54        }
55    }
56}
57
58impl TryIntoRequest for GetGlobalCommands<'_> {
59    fn try_into_request(self) -> Result<Request, Error> {
60        Ok(Request::from_route(&Route::GetGlobalCommands {
61            application_id: self.application_id.get(),
62            with_localizations: self.with_localizations,
63        }))
64    }
65}