twilight_http/request/guild/role/
get_guild_role_permissions.rs1use crate::{
4 client::Client,
5 error::Error,
6 request::{Request, TryIntoRequest},
7 response::{Response, ResponseFuture},
8 routing::Route,
9};
10use serde::Deserialize;
11use std::future::IntoFuture;
12use twilight_model::{
13 guild::Permissions,
14 id::{
15 Id,
16 marker::{GuildMarker, RoleMarker},
17 },
18};
19
20#[derive(Clone, Debug, Deserialize)]
22#[non_exhaustive]
23pub struct GetGuildRolePermissionsResponseBody {
24 pub permissions: Permissions,
26}
27
28struct GetGuildRolePermissionsPath {
29 guild_id: Id<GuildMarker>,
30 role_id: Id<RoleMarker>,
31}
32
33#[must_use = "requests must be configured and executed"]
38pub struct GetGuildRolePermissions<'a> {
39 http: &'a Client,
40 path: GetGuildRolePermissionsPath,
41}
42
43impl<'a> GetGuildRolePermissions<'a> {
44 pub(crate) const fn new(
45 http: &'a Client,
46 guild_id: Id<GuildMarker>,
47 role_id: Id<RoleMarker>,
48 ) -> Self {
49 Self {
50 http,
51 path: GetGuildRolePermissionsPath { guild_id, role_id },
52 }
53 }
54}
55
56impl IntoFuture for GetGuildRolePermissions<'_> {
57 type Output = Result<Response<GetGuildRolePermissionsResponseBody>, Error>;
58
59 type IntoFuture = ResponseFuture<GetGuildRolePermissionsResponseBody>;
60
61 fn into_future(self) -> Self::IntoFuture {
62 let http = self.http;
63
64 match self.try_into_request() {
65 Ok(request) => http.request(request),
66 Err(source) => ResponseFuture::error(source),
67 }
68 }
69}
70
71impl TryIntoRequest for GetGuildRolePermissions<'_> {
72 fn try_into_request(self) -> Result<Request, Error> {
73 let GetGuildRolePermissionsPath { guild_id, role_id } = self.path;
74
75 Ok(Request::from_route(&Route::GetGuildRolePermissions {
76 guild_id: guild_id.get(),
77 role_id: role_id.get(),
78 }))
79 }
80}