twilight_http/request/channel/
get_channel_role_permissions.rs1use crate::{
5 client::Client,
6 error::Error,
7 request::{Request, TryIntoRequest},
8 response::{Response, ResponseFuture},
9 routing::Route,
10};
11use serde::Deserialize;
12use std::future::IntoFuture;
13use twilight_model::{
14 guild::Permissions,
15 id::{
16 Id,
17 marker::{ChannelMarker, RoleMarker},
18 },
19};
20
21#[derive(Clone, Debug, Deserialize)]
23#[non_exhaustive]
24pub struct GetChannelRolePermissionsResponseBody {
25 pub permissions: Permissions,
27}
28
29struct GetChannelRolePermissionsPath {
30 channel_id: Id<ChannelMarker>,
31 implicit: Option<bool>,
32 role_id: Id<RoleMarker>,
33}
34
35#[must_use = "requests must be configured and executed"]
49pub struct GetChannelRolePermissions<'a> {
50 http: &'a Client,
51 path: GetChannelRolePermissionsPath,
52}
53
54impl<'a> GetChannelRolePermissions<'a> {
55 pub(crate) const fn new(
56 http: &'a Client,
57 channel_id: Id<ChannelMarker>,
58 role_id: Id<RoleMarker>,
59 ) -> Self {
60 Self {
61 http,
62 path: GetChannelRolePermissionsPath {
63 channel_id,
64 implicit: None,
65 role_id,
66 },
67 }
68 }
69
70 pub const fn implicit(mut self, implicit: bool) -> Self {
82 self.path.implicit = Some(implicit);
83
84 self
85 }
86}
87
88impl IntoFuture for GetChannelRolePermissions<'_> {
89 type Output = Result<Response<GetChannelRolePermissionsResponseBody>, Error>;
90
91 type IntoFuture = ResponseFuture<GetChannelRolePermissionsResponseBody>;
92
93 fn into_future(self) -> Self::IntoFuture {
94 let http = self.http;
95
96 match self.try_into_request() {
97 Ok(request) => http.request(request),
98 Err(source) => ResponseFuture::error(source),
99 }
100 }
101}
102
103impl TryIntoRequest for GetChannelRolePermissions<'_> {
104 fn try_into_request(self) -> Result<Request, Error> {
105 let GetChannelRolePermissionsPath {
106 channel_id,
107 implicit,
108 role_id,
109 } = self.path;
110
111 Ok(Request::from_route(&Route::GetChannelRolePermissions {
112 channel_id: channel_id.get(),
113 implicit,
114 role_id: role_id.get(),
115 }))
116 }
117}