twilight_http/request/guild/ban/
delete_ban.rs1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture, marker::EmptyBody};
3use crate::{
4 client::Client,
5 error::Error,
6 request::{self, AuditLogReason, Request, TryIntoRequest},
7 routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::id::{
11 Id,
12 marker::{GuildMarker, UserMarker},
13};
14use twilight_validate::request::{ValidationError, audit_reason as validate_audit_reason};
15
16#[must_use = "requests must be configured and executed"]
37pub struct DeleteBan<'a> {
38 guild_id: Id<GuildMarker>,
39 http: &'a Client,
40 user_id: Id<UserMarker>,
41 reason: Result<Option<&'a str>, ValidationError>,
42}
43
44impl<'a> DeleteBan<'a> {
45 pub(crate) const fn new(
46 http: &'a Client,
47 guild_id: Id<GuildMarker>,
48 user_id: Id<UserMarker>,
49 ) -> Self {
50 Self {
51 guild_id,
52 http,
53 user_id,
54 reason: Ok(None),
55 }
56 }
57}
58
59impl<'a> AuditLogReason<'a> for DeleteBan<'a> {
60 fn reason(mut self, reason: &'a str) -> Self {
61 self.reason = validate_audit_reason(reason).and(Ok(Some(reason)));
62
63 self
64 }
65}
66
67#[cfg(not(target_os = "wasi"))]
68impl IntoFuture for DeleteBan<'_> {
69 type Output = Result<Response<EmptyBody>, Error>;
70
71 type IntoFuture = ResponseFuture<EmptyBody>;
72
73 fn into_future(self) -> Self::IntoFuture {
74 let http = self.http;
75
76 match self.try_into_request() {
77 Ok(request) => http.request(request),
78 Err(source) => ResponseFuture::error(source),
79 }
80 }
81}
82
83impl TryIntoRequest for DeleteBan<'_> {
84 fn try_into_request(self) -> Result<Request, Error> {
85 let mut request = Request::builder(&Route::DeleteBan {
86 guild_id: self.guild_id.get(),
87 user_id: self.user_id.get(),
88 });
89
90 if let Some(reason) = self.reason.map_err(Error::validation)? {
91 request = request.headers(request::audit_header(reason)?);
92 }
93
94 request.build()
95 }
96}