Skip to main content

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