twilight_http/request/channel/
delete_channel_permission_configured.rs

1use 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_model::id::{marker::ChannelMarker, Id};
10use twilight_validate::request::{audit_reason as validate_audit_reason, ValidationError};
11
12/// Clear the permissions for a target ID in a channel.
13///
14/// The `target_id` is a `u64`, but it should point to a `Id<RoleMarker>` or a `Id<UserMarker>`.
15#[must_use = "requests must be configured and executed"]
16pub struct DeleteChannelPermissionConfigured<'a> {
17    channel_id: Id<ChannelMarker>,
18    http: &'a Client,
19    reason: Result<Option<&'a str>, ValidationError>,
20    target_id: u64,
21}
22
23impl<'a> DeleteChannelPermissionConfigured<'a> {
24    pub(crate) const fn new(
25        http: &'a Client,
26        channel_id: Id<ChannelMarker>,
27        target_id: u64,
28    ) -> Self {
29        Self {
30            channel_id,
31            http,
32            reason: Ok(None),
33            target_id,
34        }
35    }
36}
37
38impl<'a> AuditLogReason<'a> for DeleteChannelPermissionConfigured<'a> {
39    fn reason(mut self, reason: &'a str) -> Self {
40        self.reason = validate_audit_reason(reason).and(Ok(Some(reason)));
41
42        self
43    }
44}
45
46impl IntoFuture for DeleteChannelPermissionConfigured<'_> {
47    type Output = Result<Response<EmptyBody>, Error>;
48
49    type IntoFuture = ResponseFuture<EmptyBody>;
50
51    fn into_future(self) -> Self::IntoFuture {
52        let http = self.http;
53
54        match self.try_into_request() {
55            Ok(request) => http.request(request),
56            Err(source) => ResponseFuture::error(source),
57        }
58    }
59}
60
61impl TryIntoRequest for DeleteChannelPermissionConfigured<'_> {
62    fn try_into_request(self) -> Result<Request, Error> {
63        let mut request = Request::builder(&Route::DeletePermissionOverwrite {
64            channel_id: self.channel_id.get(),
65            target_id: self.target_id,
66        });
67
68        if let Some(reason) = self.reason.map_err(Error::validation)? {
69            request = request.headers(request::audit_header(reason)?);
70        }
71
72        request.build()
73    }
74}