Skip to main content

twilight_http/request/guild/role/
get_guild_role_member_counts.rs

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