Skip to main content

twilight_http/request/guild/integration/
get_guild_integrations.rs

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