twilight_http/request/guild/
get_guild_welcome_screen.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::{
10    guild::invite::WelcomeScreen,
11    id::{marker::GuildMarker, Id},
12};
13
14/// Get the guild's welcome screen.
15///
16/// If the welcome screen is not enabled, this requires the [`MANAGE_GUILD`]
17/// permission.
18///
19/// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
20#[must_use = "requests must be configured and executed"]
21pub struct GetGuildWelcomeScreen<'a> {
22    guild_id: Id<GuildMarker>,
23    http: &'a Client,
24}
25
26impl<'a> GetGuildWelcomeScreen<'a> {
27    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
28        Self { guild_id, http }
29    }
30}
31
32impl IntoFuture for GetGuildWelcomeScreen<'_> {
33    type Output = Result<Response<WelcomeScreen>, Error>;
34
35    type IntoFuture = ResponseFuture<WelcomeScreen>;
36
37    fn into_future(self) -> Self::IntoFuture {
38        let http = self.http;
39
40        match self.try_into_request() {
41            Ok(request) => http.request(request),
42            Err(source) => ResponseFuture::error(source),
43        }
44    }
45}
46
47impl TryIntoRequest for GetGuildWelcomeScreen<'_> {
48    fn try_into_request(self) -> Result<Request, Error> {
49        Ok(Request::from_route(&Route::GetGuildWelcomeScreen {
50            guild_id: self.guild_id.get(),
51        }))
52    }
53}