Skip to main content

twilight_http/request/
get_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::voice::VoiceRegion;
11
12/// Get a list of voice regions that can be used when creating a guild.
13#[must_use = "requests must be configured and executed"]
14pub struct GetVoiceRegions<'a> {
15    http: &'a Client,
16}
17
18impl<'a> GetVoiceRegions<'a> {
19    pub(crate) const fn new(http: &'a Client) -> Self {
20        Self { http }
21    }
22}
23
24#[cfg(not(target_os = "wasi"))]
25impl IntoFuture for GetVoiceRegions<'_> {
26    type Output = Result<Response<ListBody<VoiceRegion>>, Error>;
27
28    type IntoFuture = ResponseFuture<ListBody<VoiceRegion>>;
29
30    fn into_future(self) -> Self::IntoFuture {
31        let http = self.http;
32
33        match self.try_into_request() {
34            Ok(request) => http.request(request),
35            Err(source) => ResponseFuture::error(source),
36        }
37    }
38}
39
40impl TryIntoRequest for GetVoiceRegions<'_> {
41    fn try_into_request(self) -> Result<Request, Error> {
42        Ok(Request::from_route(&Route::GetVoiceRegions))
43    }
44}