twilight_http/request/guild/integration/
get_guild_integrations.rs

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