twilight_http/request/application/command/
get_guild_command.rs

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