twilight_http/request/guild/user/
get_current_user_voice_state.rs

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