Skip to main content

twilight_http/request/sticker/
get_nitro_sticker_packs.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 serde::Deserialize;
10use std::future::IntoFuture;
11use twilight_model::channel::message::sticker::StickerPack;
12
13#[derive(Deserialize)]
14pub struct StickerPackListing {
15    pub sticker_packs: Vec<StickerPack>,
16}
17
18/// Returns a list of sticker packs available to Nitro subscribers.
19///
20/// # Examples
21///
22/// ```no_run
23/// use twilight_http::Client;
24///
25/// # #[tokio::main]
26/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
27/// let client = Client::new("my token".to_owned());
28///
29/// let packs = client.nitro_sticker_packs().await?.model().await?;
30///
31/// println!("{}", packs.sticker_packs.len());
32/// # Ok(()) }
33/// ```
34#[must_use = "requests must be configured and executed"]
35pub struct GetNitroStickerPacks<'a> {
36    http: &'a Client,
37}
38
39impl<'a> GetNitroStickerPacks<'a> {
40    pub(crate) const fn new(http: &'a Client) -> Self {
41        Self { http }
42    }
43}
44
45#[cfg(not(target_os = "wasi"))]
46impl IntoFuture for GetNitroStickerPacks<'_> {
47    type Output = Result<Response<StickerPackListing>, Error>;
48
49    type IntoFuture = ResponseFuture<StickerPackListing>;
50
51    fn into_future(self) -> Self::IntoFuture {
52        let http = self.http;
53
54        match self.try_into_request() {
55            Ok(request) => http.request(request),
56            Err(source) => ResponseFuture::error(source),
57        }
58    }
59}
60
61impl TryIntoRequest for GetNitroStickerPacks<'_> {
62    fn try_into_request(self) -> Result<Request, Error> {
63        Ok(Request::from_route(&Route::GetNitroStickerPacks))
64    }
65}