Skip to main content

twilight_http/request/application/command/
get_guild_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, GuildMarker},
15    },
16};
17
18/// Retrieve a global command for an application.
19#[must_use = "requests must be configured and executed"]
20pub struct GetGuildCommand<'a> {
21    application_id: Id<ApplicationMarker>,
22    command_id: Id<CommandMarker>,
23    guild_id: Id<GuildMarker>,
24    http: &'a Client,
25}
26
27impl<'a> GetGuildCommand<'a> {
28    pub(crate) const fn new(
29        http: &'a Client,
30        application_id: Id<ApplicationMarker>,
31        guild_id: Id<GuildMarker>,
32        command_id: Id<CommandMarker>,
33    ) -> Self {
34        Self {
35            application_id,
36            command_id,
37            guild_id,
38            http,
39        }
40    }
41}
42
43#[cfg(not(target_os = "wasi"))]
44impl IntoFuture for GetGuildCommand<'_> {
45    type Output = Result<Response<Command>, Error>;
46
47    type IntoFuture = ResponseFuture<Command>;
48
49    fn into_future(self) -> Self::IntoFuture {
50        let http = self.http;
51
52        match self.try_into_request() {
53            Ok(request) => http.request(request),
54            Err(source) => ResponseFuture::error(source),
55        }
56    }
57}
58
59impl TryIntoRequest for GetGuildCommand<'_> {
60    fn try_into_request(self) -> Result<Request, Error> {
61        Ok(Request::from_route(&Route::GetGuildCommand {
62            application_id: self.application_id.get(),
63            command_id: self.command_id.get(),
64            guild_id: self.guild_id.get(),
65        }))
66    }
67}