Skip to main content

twilight_http/request/guild/sticker/
get_guild_sticker.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    channel::message::sticker::Sticker,
12    id::{
13        Id,
14        marker::{GuildMarker, StickerMarker},
15    },
16};
17
18/// Returns a guild sticker by the guild's ID and the sticker's ID.
19///
20/// # Examples
21///
22/// ```no_run
23/// use twilight_http::Client;
24/// use twilight_model::id::Id;
25///
26/// # #[tokio::main]
27/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
28/// let client = Client::new("my token".to_owned());
29///
30/// let guild_id = Id::new(1);
31/// let sticker_id = Id::new(2);
32/// let sticker = client
33///     .guild_sticker(guild_id, sticker_id)
34///     .await?
35///     .model()
36///     .await?;
37///
38/// println!("{sticker:#?}");
39/// # Ok(()) }
40/// ```
41pub struct GetGuildSticker<'a> {
42    guild_id: Id<GuildMarker>,
43    http: &'a Client,
44    sticker_id: Id<StickerMarker>,
45}
46
47impl<'a> GetGuildSticker<'a> {
48    pub(crate) const fn new(
49        http: &'a Client,
50        guild_id: Id<GuildMarker>,
51        sticker_id: Id<StickerMarker>,
52    ) -> Self {
53        Self {
54            guild_id,
55            http,
56            sticker_id,
57        }
58    }
59}
60
61#[cfg(not(target_os = "wasi"))]
62impl IntoFuture for GetGuildSticker<'_> {
63    type Output = Result<Response<Sticker>, Error>;
64
65    type IntoFuture = ResponseFuture<Sticker>;
66
67    fn into_future(self) -> Self::IntoFuture {
68        let http = self.http;
69
70        match self.try_into_request() {
71            Ok(request) => http.request(request),
72            Err(source) => ResponseFuture::error(source),
73        }
74    }
75}
76
77impl TryIntoRequest for GetGuildSticker<'_> {
78    fn try_into_request(self) -> Result<Request, Error> {
79        Ok(Request::from_route(&Route::GetGuildSticker {
80            guild_id: self.guild_id.get(),
81            sticker_id: self.sticker_id.get(),
82        }))
83    }
84}