twilight_http/request/channel/invite/
delete_invite.rs1use crate::{
2 client::Client,
3 error::Error,
4 request::{self, AuditLogReason, Request, TryIntoRequest},
5 response::{marker::EmptyBody, Response, ResponseFuture},
6 routing::Route,
7};
8use std::future::IntoFuture;
9use twilight_validate::request::{audit_reason as validate_audit_reason, ValidationError};
10
11#[must_use = "requests must be configured and executed"]
19pub struct DeleteInvite<'a> {
20 code: &'a str,
21 http: &'a Client,
22 reason: Result<Option<&'a str>, ValidationError>,
23}
24
25impl<'a> DeleteInvite<'a> {
26 pub(crate) const fn new(http: &'a Client, code: &'a str) -> Self {
27 Self {
28 code,
29 http,
30 reason: Ok(None),
31 }
32 }
33}
34
35impl<'a> AuditLogReason<'a> for DeleteInvite<'a> {
36 fn reason(mut self, reason: &'a str) -> Self {
37 self.reason = validate_audit_reason(reason).and(Ok(Some(reason)));
38
39 self
40 }
41}
42
43impl IntoFuture for DeleteInvite<'_> {
44 type Output = Result<Response<EmptyBody>, Error>;
45
46 type IntoFuture = ResponseFuture<EmptyBody>;
47
48 fn into_future(self) -> Self::IntoFuture {
49 let http = self.http;
50
51 match self.try_into_request() {
52 Ok(request) => http.request(request),
53 Err(source) => ResponseFuture::error(source),
54 }
55 }
56}
57
58impl TryIntoRequest for DeleteInvite<'_> {
59 fn try_into_request(self) -> Result<Request, Error> {
60 let mut request = Request::builder(&Route::DeleteInvite { code: self.code });
61
62 if let Some(reason) = self.reason.map_err(Error::validation)? {
63 request = request.headers(request::audit_header(reason)?);
64 }
65
66 request.build()
67 }
68}