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