twilight_http/request/guild/
delete_guild.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::{marker::GuildMarker, Id};
10
11/// Delete a guild permanently. The user must be the owner.
12#[must_use = "requests must be configured and executed"]
13pub struct DeleteGuild<'a> {
14    guild_id: Id<GuildMarker>,
15    http: &'a Client,
16}
17
18impl<'a> DeleteGuild<'a> {
19    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
20        Self { guild_id, http }
21    }
22}
23
24impl IntoFuture for DeleteGuild<'_> {
25    type Output = Result<Response<EmptyBody>, Error>;
26
27    type IntoFuture = ResponseFuture<EmptyBody>;
28
29    fn into_future(self) -> Self::IntoFuture {
30        let http = self.http;
31
32        match self.try_into_request() {
33            Ok(request) => http.request(request),
34            Err(source) => ResponseFuture::error(source),
35        }
36    }
37}
38
39impl TryIntoRequest for DeleteGuild<'_> {
40    fn try_into_request(self) -> Result<Request, Error> {
41        Ok(Request::from_route(&Route::DeleteGuild {
42            guild_id: self.guild_id.get(),
43        }))
44    }
45}