Skip to main content

twilight_http/request/user/
get_current_user.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::user::CurrentUser;
11
12/// Get information about the current user.
13#[must_use = "requests must be configured and executed"]
14pub struct GetCurrentUser<'a> {
15    http: &'a Client,
16}
17
18impl<'a> GetCurrentUser<'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 GetCurrentUser<'_> {
26    type Output = Result<Response<CurrentUser>, Error>;
27
28    type IntoFuture = ResponseFuture<CurrentUser>;
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 GetCurrentUser<'_> {
41    fn try_into_request(self) -> Result<Request, Error> {
42        Ok(Request::from_route(&Route::GetCurrentUser))
43    }
44}