Skip to main content

twilight_http/request/sticker/
get_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::{Id, marker::StickerMarker},
13};
14
15/// Returns a single sticker by its ID.
16///
17/// # Examples
18///
19/// ```no_run
20/// use twilight_http::Client;
21/// use twilight_model::id::Id;
22///
23/// # #[tokio::main]
24/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
25/// let client = Client::new("my token".to_owned());
26///
27/// let id = Id::new(123);
28/// let sticker = client.sticker(id).await?.model().await?;
29/// # Ok(()) }
30/// ```
31#[must_use = "requests must be configured and executed"]
32pub struct GetSticker<'a> {
33    http: &'a Client,
34    sticker_id: Id<StickerMarker>,
35}
36
37impl<'a> GetSticker<'a> {
38    pub(crate) const fn new(http: &'a Client, sticker_id: Id<StickerMarker>) -> Self {
39        Self { http, sticker_id }
40    }
41}
42
43#[cfg(not(target_os = "wasi"))]
44impl IntoFuture for GetSticker<'_> {
45    type Output = Result<Response<Sticker>, Error>;
46
47    type IntoFuture = ResponseFuture<Sticker>;
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 GetSticker<'_> {
60    fn try_into_request(self) -> Result<Request, Error> {
61        Ok(Request::from_route(&Route::GetSticker {
62            sticker_id: self.sticker_id.get(),
63        }))
64    }
65}