twilight_http/request/sticker/
get_nitro_sticker_packs.rs

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