Skip to main content

twilight_http/request/user/
get_current_user_guild_member.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture};
3use crate::{
4    Error,
5    client::Client,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::{
11    guild::Member,
12    id::{Id, marker::GuildMarker},
13};
14
15/// Get information about the current user in a guild.
16#[must_use = "requests must be configured and executed"]
17pub struct GetCurrentUserGuildMember<'a> {
18    guild_id: Id<GuildMarker>,
19    http: &'a Client,
20}
21
22impl<'a> GetCurrentUserGuildMember<'a> {
23    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
24        Self { guild_id, http }
25    }
26}
27
28#[cfg(not(target_os = "wasi"))]
29impl IntoFuture for GetCurrentUserGuildMember<'_> {
30    type Output = Result<Response<Member>, Error>;
31
32    type IntoFuture = ResponseFuture<Member>;
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 GetCurrentUserGuildMember<'_> {
45    fn try_into_request(self) -> Result<Request, Error> {
46        Ok(Request::from_route(&Route::GetCurrentUserGuildMember {
47            guild_id: self.guild_id.get(),
48        }))
49    }
50}