Skip to main content

twilight_http/request/guild/sticker/
get_guild_stickers.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::{
11    channel::message::sticker::Sticker,
12    id::{Id, marker::GuildMarker},
13};
14
15/// Returns a list of stickers in a guild.
16///
17/// # Examples
18///
19/// ```no_run
20/// use twilight_http::Client;
21/// use twilight_model::id::Id;
22///
23/// # #[tokio::main]
24/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
25/// let client = Client::new("my token".to_owned());
26///
27/// let guild_id = Id::new(1);
28/// let stickers = client.guild_stickers(guild_id).await?.models().await?;
29///
30/// println!("{}", stickers.len());
31/// # Ok(()) }
32/// ```
33pub struct GetGuildStickers<'a> {
34    guild_id: Id<GuildMarker>,
35    http: &'a Client,
36}
37
38impl<'a> GetGuildStickers<'a> {
39    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
40        Self { guild_id, http }
41    }
42}
43
44#[cfg(not(target_os = "wasi"))]
45impl IntoFuture for GetGuildStickers<'_> {
46    type Output = Result<Response<ListBody<Sticker>>, Error>;
47
48    type IntoFuture = ResponseFuture<ListBody<Sticker>>;
49
50    fn into_future(self) -> Self::IntoFuture {
51        let http = self.http;
52
53        match self.try_into_request() {
54            Ok(request) => http.request(request),
55            Err(source) => ResponseFuture::error(source),
56        }
57    }
58}
59
60impl TryIntoRequest for GetGuildStickers<'_> {
61    fn try_into_request(self) -> Result<Request, Error> {
62        Ok(Request::from_route(&Route::GetGuildStickers {
63            guild_id: self.guild_id.get(),
64        }))
65    }
66}