twilight_http/request/user/
get_current_user.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::user::CurrentUser;
10
11/// Get information about the current user.
12#[must_use = "requests must be configured and executed"]
13pub struct GetCurrentUser<'a> {
14    http: &'a Client,
15}
16
17impl<'a> GetCurrentUser<'a> {
18    pub(crate) const fn new(http: &'a Client) -> Self {
19        Self { http }
20    }
21}
22
23impl IntoFuture for GetCurrentUser<'_> {
24    type Output = Result<Response<CurrentUser>, Error>;
25
26    type IntoFuture = ResponseFuture<CurrentUser>;
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 GetCurrentUser<'_> {
39    fn try_into_request(self) -> Result<Request, Error> {
40        Ok(Request::from_route(&Route::GetCurrentUser))
41    }
42}