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