twilight_http/request/application/command/
get_global_commands.rs

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