twilight_http/request/guild/
get_guild_voice_regions.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    id::{marker::GuildMarker, Id},
11    voice::VoiceRegion,
12};
13
14/// Get voice region data for the guild.
15///
16/// Can return VIP servers if the guild is VIP-enabled.
17#[must_use = "requests must be configured and executed"]
18pub struct GetGuildVoiceRegions<'a> {
19    guild_id: Id<GuildMarker>,
20    http: &'a Client,
21}
22
23impl<'a> GetGuildVoiceRegions<'a> {
24    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
25        Self { guild_id, http }
26    }
27}
28
29impl IntoFuture for GetGuildVoiceRegions<'_> {
30    type Output = Result<Response<ListBody<VoiceRegion>>, Error>;
31
32    type IntoFuture = ResponseFuture<ListBody<VoiceRegion>>;
33
34    fn into_future(self) -> Self::IntoFuture {
35        let http = self.http;
36
37        match self.try_into_request() {
38            Ok(request) => http.request(request),
39            Err(source) => ResponseFuture::error(source),
40        }
41    }
42}
43
44impl TryIntoRequest for GetGuildVoiceRegions<'_> {
45    fn try_into_request(self) -> Result<Request, Error> {
46        Ok(Request::from_route(&Route::GetGuildVoiceRegions {
47            guild_id: self.guild_id.get(),
48        }))
49    }
50}