Skip to main content

twilight_http/request/guild/ban/
get_ban.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::{
11    guild::Ban,
12    id::{
13        Id,
14        marker::{GuildMarker, UserMarker},
15    },
16};
17
18/// Get information about a ban of a guild.
19///
20/// Includes the user banned and the reason.
21#[must_use = "requests must be configured and executed"]
22pub struct GetBan<'a> {
23    guild_id: Id<GuildMarker>,
24    http: &'a Client,
25    user_id: Id<UserMarker>,
26}
27
28impl<'a> GetBan<'a> {
29    pub(crate) const fn new(
30        http: &'a Client,
31        guild_id: Id<GuildMarker>,
32        user_id: Id<UserMarker>,
33    ) -> Self {
34        Self {
35            guild_id,
36            http,
37            user_id,
38        }
39    }
40}
41
42#[cfg(not(target_os = "wasi"))]
43impl IntoFuture for GetBan<'_> {
44    type Output = Result<Response<Ban>, Error>;
45
46    type IntoFuture = ResponseFuture<Ban>;
47
48    fn into_future(self) -> Self::IntoFuture {
49        let http = self.http;
50
51        match self.try_into_request() {
52            Ok(request) => http.request(request),
53            Err(source) => ResponseFuture::error(source),
54        }
55    }
56}
57
58impl TryIntoRequest for GetBan<'_> {
59    fn try_into_request(self) -> Result<Request, Error> {
60        Ok(Request::from_route(&Route::GetBan {
61            guild_id: self.guild_id.get(),
62            user_id: self.user_id.get(),
63        }))
64    }
65}