twilight_http/request/template/
delete_template.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 template by ID and code.
12#[must_use = "requests must be configured and executed"]
13pub struct DeleteTemplate<'a> {
14    guild_id: Id<GuildMarker>,
15    http: &'a Client,
16    template_code: &'a str,
17}
18
19impl<'a> DeleteTemplate<'a> {
20    pub(crate) const fn new(
21        http: &'a Client,
22        guild_id: Id<GuildMarker>,
23        template_code: &'a str,
24    ) -> Self {
25        Self {
26            guild_id,
27            http,
28            template_code,
29        }
30    }
31}
32
33impl IntoFuture for DeleteTemplate<'_> {
34    type Output = Result<Response<EmptyBody>, Error>;
35
36    type IntoFuture = ResponseFuture<EmptyBody>;
37
38    fn into_future(self) -> Self::IntoFuture {
39        let http = self.http;
40
41        match self.try_into_request() {
42            Ok(request) => http.request(request),
43            Err(source) => ResponseFuture::error(source),
44        }
45    }
46}
47
48impl TryIntoRequest for DeleteTemplate<'_> {
49    fn try_into_request(self) -> Result<Request, Error> {
50        Ok(Request::from_route(&Route::DeleteTemplate {
51            guild_id: self.guild_id.get(),
52            template_code: self.template_code,
53        }))
54    }
55}