Skip to main content

twilight_http/request/guild/sticker/
delete_guild_sticker.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture, marker::EmptyBody};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::id::{
11    Id,
12    marker::{GuildMarker, StickerMarker},
13};
14
15/// Deletes a guild sticker by the ID of the guild and 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 guild_id = Id::new(1);
28/// let sticker_id = Id::new(2);
29///
30/// client.delete_guild_sticker(guild_id, sticker_id).await?;
31/// # Ok(()) }
32/// ```
33pub struct DeleteGuildSticker<'a> {
34    guild_id: Id<GuildMarker>,
35    http: &'a Client,
36    sticker_id: Id<StickerMarker>,
37}
38
39impl<'a> DeleteGuildSticker<'a> {
40    pub(crate) const fn new(
41        http: &'a Client,
42        guild_id: Id<GuildMarker>,
43        sticker_id: Id<StickerMarker>,
44    ) -> Self {
45        Self {
46            guild_id,
47            http,
48            sticker_id,
49        }
50    }
51}
52
53#[cfg(not(target_os = "wasi"))]
54impl IntoFuture for DeleteGuildSticker<'_> {
55    type Output = Result<Response<EmptyBody>, Error>;
56
57    type IntoFuture = ResponseFuture<EmptyBody>;
58
59    fn into_future(self) -> Self::IntoFuture {
60        let http = self.http;
61
62        match self.try_into_request() {
63            Ok(request) => http.request(request),
64            Err(source) => ResponseFuture::error(source),
65        }
66    }
67}
68
69impl TryIntoRequest for DeleteGuildSticker<'_> {
70    fn try_into_request(self) -> Result<Request, Error> {
71        Ok(Request::from_route(&Route::DeleteGuildSticker {
72            guild_id: self.guild_id.get(),
73            sticker_id: self.sticker_id.get(),
74        }))
75    }
76}