Skip to main content

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