Skip to main content

twilight_http/request/user/
get_current_user_connections.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture, marker::ListBody};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::user::Connection;
11
12/// Get the current user's connections.
13///
14/// Requires the `connections` `OAuth2` scope.
15#[must_use = "requests must be configured and executed"]
16pub struct GetCurrentUserConnections<'a> {
17    http: &'a Client,
18}
19
20impl<'a> GetCurrentUserConnections<'a> {
21    pub(crate) const fn new(http: &'a Client) -> Self {
22        Self { http }
23    }
24}
25
26#[cfg(not(target_os = "wasi"))]
27impl IntoFuture for GetCurrentUserConnections<'_> {
28    type Output = Result<Response<ListBody<Connection>>, Error>;
29
30    type IntoFuture = ResponseFuture<ListBody<Connection>>;
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 GetCurrentUserConnections<'_> {
43    fn try_into_request(self) -> Result<Request, Error> {
44        Ok(Request::from_route(&Route::GetUserConnections))
45    }
46}