Skip to main content

twilight_http/request/guild/
get_guild_widget.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::widget::GuildWidget,
12    id::{Id, marker::GuildMarker},
13};
14
15/// Get a guild's widget
16///
17/// See [Discord Docs/Get Guild Widget].
18///
19/// [Discord Docs/Get Guild Widget]: https://discord.com/developers/docs/resources/guild#get-guild-widget
20#[must_use = "requests must be configured and executed"]
21pub struct GetGuildWidget<'a> {
22    guild_id: Id<GuildMarker>,
23    http: &'a Client,
24}
25
26impl<'a> GetGuildWidget<'a> {
27    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
28        Self { guild_id, http }
29    }
30}
31
32#[cfg(not(target_os = "wasi"))]
33impl IntoFuture for GetGuildWidget<'_> {
34    type Output = Result<Response<GuildWidget>, Error>;
35
36    type IntoFuture = ResponseFuture<GuildWidget>;
37
38    fn into_future(self) -> Self::IntoFuture {
39        let http = self.http;
40
41        match self.try_into_request() {
42            Ok(request) => http.request(request),
43            Err(source) => ResponseFuture::error(source),
44        }
45    }
46}
47
48impl TryIntoRequest for GetGuildWidget<'_> {
49    fn try_into_request(self) -> Result<Request, Error> {
50        Ok(Request::from_route(&Route::GetGuildWidget {
51            guild_id: self.guild_id.get(),
52        }))
53    }
54}