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