twilight_http/request/channel/invite/
get_invite.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::invite::Invite;
11
12struct GetInviteFields {
13 with_counts: bool,
14 with_expiration: bool,
15}
16
17#[must_use = "requests must be configured and executed"]
39pub struct GetInvite<'a> {
40 code: &'a str,
41 fields: GetInviteFields,
42 http: &'a Client,
43}
44
45impl<'a> GetInvite<'a> {
46 pub(crate) const fn new(http: &'a Client, code: &'a str) -> Self {
47 Self {
48 code,
49 fields: GetInviteFields {
50 with_counts: false,
51 with_expiration: false,
52 },
53 http,
54 }
55 }
56
57 pub const fn with_counts(mut self) -> Self {
59 self.fields.with_counts = true;
60
61 self
62 }
63
64 pub const fn with_expiration(mut self) -> Self {
66 self.fields.with_expiration = true;
67
68 self
69 }
70}
71
72#[cfg(not(target_os = "wasi"))]
73impl IntoFuture for GetInvite<'_> {
74 type Output = Result<Response<Invite>, Error>;
75
76 type IntoFuture = ResponseFuture<Invite>;
77
78 fn into_future(self) -> Self::IntoFuture {
79 let http = self.http;
80
81 match self.try_into_request() {
82 Ok(request) => http.request(request),
83 Err(source) => ResponseFuture::error(source),
84 }
85 }
86}
87
88impl TryIntoRequest for GetInvite<'_> {
89 fn try_into_request(self) -> Result<Request, Error> {
90 Ok(Request::from_route(&Route::GetInviteWithExpiration {
91 code: self.code,
92 with_counts: self.fields.with_counts,
93 with_expiration: self.fields.with_expiration,
94 }))
95 }
96}