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