twilight_http/request/application/command/
delete_guild_command.rs

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