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