Skip to main content

twilight_http/request/application/command/
get_global_command.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::{
11    application::command::Command,
12    id::{
13        Id,
14        marker::{ApplicationMarker, CommandMarker},
15    },
16};
17
18/// Retrieve a global command for an application.
19#[must_use = "requests must be configured and executed"]
20pub struct GetGlobalCommand<'a> {
21    application_id: Id<ApplicationMarker>,
22    command_id: Id<CommandMarker>,
23    http: &'a Client,
24}
25
26impl<'a> GetGlobalCommand<'a> {
27    pub(crate) const fn new(
28        http: &'a Client,
29        application_id: Id<ApplicationMarker>,
30        command_id: Id<CommandMarker>,
31    ) -> Self {
32        Self {
33            application_id,
34            command_id,
35            http,
36        }
37    }
38}
39
40#[cfg(not(target_os = "wasi"))]
41impl IntoFuture for GetGlobalCommand<'_> {
42    type Output = Result<Response<Command>, Error>;
43
44    type IntoFuture = ResponseFuture<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 GetGlobalCommand<'_> {
57    fn try_into_request(self) -> Result<Request, Error> {
58        Ok(Request::from_route(&Route::GetGlobalCommand {
59            application_id: self.application_id.get(),
60            command_id: self.command_id.get(),
61        }))
62    }
63}