twilight_http/request/guild/sticker/
get_guild_sticker.rs

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