twilight_http/request/channel/
get_channel_member_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, UserMarker},
18 },
19};
20
21#[derive(Clone, Debug, Deserialize)]
23#[non_exhaustive]
24pub struct GetChannelMemberPermissionsResponseBody {
25 pub permissions: Permissions,
27}
28
29struct GetChannelMemberPermissionsPath {
30 channel_id: Id<ChannelMarker>,
31 implicit: Option<bool>,
32 user_id: Id<UserMarker>,
33}
34
35#[must_use = "requests must be configured and executed"]
48pub struct GetChannelMemberPermissions<'a> {
49 http: &'a Client,
50 path: GetChannelMemberPermissionsPath,
51}
52
53impl<'a> GetChannelMemberPermissions<'a> {
54 pub(crate) const fn new(
55 http: &'a Client,
56 channel_id: Id<ChannelMarker>,
57 user_id: Id<UserMarker>,
58 ) -> Self {
59 Self {
60 http,
61 path: GetChannelMemberPermissionsPath {
62 channel_id,
63 implicit: None,
64 user_id,
65 },
66 }
67 }
68
69 pub const fn implicit(mut self, implicit: bool) -> Self {
82 self.path.implicit = Some(implicit);
83
84 self
85 }
86}
87
88impl IntoFuture for GetChannelMemberPermissions<'_> {
89 type Output = Result<Response<GetChannelMemberPermissionsResponseBody>, Error>;
90
91 type IntoFuture = ResponseFuture<GetChannelMemberPermissionsResponseBody>;
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 GetChannelMemberPermissions<'_> {
104 fn try_into_request(self) -> Result<Request, Error> {
105 let GetChannelMemberPermissionsPath {
106 channel_id,
107 implicit,
108 user_id,
109 } = self.path;
110
111 Ok(Request::from_route(&Route::GetChannelMemberPermissions {
112 channel_id: channel_id.get(),
113 implicit,
114 user_id: user_id.get(),
115 }))
116 }
117}