Skip to main content

twilight_http/request/application/command/
delete_guild_command.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture, marker::EmptyBody};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::id::{
11    Id,
12    marker::{ApplicationMarker, CommandMarker, GuildMarker},
13};
14
15/// Delete a command in a guild, by ID.
16#[must_use = "requests must be configured and executed"]
17pub struct DeleteGuildCommand<'a> {
18    application_id: Id<ApplicationMarker>,
19    command_id: Id<CommandMarker>,
20    guild_id: Id<GuildMarker>,
21    http: &'a Client,
22}
23
24impl<'a> DeleteGuildCommand<'a> {
25    pub(crate) const fn new(
26        http: &'a Client,
27        application_id: Id<ApplicationMarker>,
28        guild_id: Id<GuildMarker>,
29        command_id: Id<CommandMarker>,
30    ) -> Self {
31        Self {
32            application_id,
33            command_id,
34            guild_id,
35            http,
36        }
37    }
38}
39
40#[cfg(not(target_os = "wasi"))]
41impl IntoFuture for DeleteGuildCommand<'_> {
42    type Output = Result<Response<EmptyBody>, Error>;
43
44    type IntoFuture = ResponseFuture<EmptyBody>;
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 DeleteGuildCommand<'_> {
57    fn try_into_request(self) -> Result<Request, Error> {
58        Ok(Request::from_route(&Route::DeleteGuildCommand {
59            application_id: self.application_id.get(),
60            command_id: self.command_id.get(),
61            guild_id: self.guild_id.get(),
62        }))
63    }
64}