twilight_http/request/guild/sticker/
get_guild_stickers.rs

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