twilight_http/request/template/
sync_template.rs

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