twilight_http/request/guild/role/
get_guild_role_member_counts.rs1use crate::{
2 client::Client,
3 error::Error,
4 request::{Request, TryIntoRequest},
5 response::{Response, ResponseFuture},
6 routing::Route,
7};
8use std::{collections::HashMap, future::IntoFuture};
9use twilight_model::id::{
10 Id,
11 marker::{GuildMarker, RoleMarker},
12};
13
14#[must_use = "requests must be configured and executed"]
15pub struct GetGuildRoleMemberCounts<'a> {
16 guild_id: Id<GuildMarker>,
17 http: &'a Client,
18}
19
20impl<'a> GetGuildRoleMemberCounts<'a> {
21 pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
22 Self { guild_id, http }
23 }
24}
25
26impl IntoFuture for GetGuildRoleMemberCounts<'_> {
27 type Output = Result<Response<HashMap<Id<RoleMarker>, u64>>, Error>;
28
29 type IntoFuture = ResponseFuture<HashMap<Id<RoleMarker>, u64>>;
30
31 fn into_future(self) -> Self::IntoFuture {
32 let http = self.http;
33
34 match self.try_into_request() {
35 Ok(request) => http.request(request),
36 Err(source) => ResponseFuture::error(source),
37 }
38 }
39}
40
41impl TryIntoRequest for GetGuildRoleMemberCounts<'_> {
42 fn try_into_request(self) -> Result<Request, Error> {
43 Ok(Request::from_route(&Route::GetGuildRoleMemberCounts {
44 guild_id: self.guild_id.get(),
45 }))
46 }
47}