Skip to main content

twilight_http/request/application/emoji/
update_emoji.rs

1use serde::Serialize;
2use std::future::IntoFuture;
3use twilight_model::{
4    guild::Emoji,
5    id::{
6        Id,
7        marker::{ApplicationMarker, EmojiMarker},
8    },
9};
10
11#[cfg(not(target_os = "wasi"))]
12use crate::response::{Response, ResponseFuture};
13use crate::{
14    Client, Error,
15    request::{Request, TryIntoRequest},
16    routing::Route,
17};
18
19#[derive(Serialize)]
20struct EditApplicationEmojiFields<'a> {
21    name: &'a str,
22}
23
24pub struct UpdateApplicationEmoji<'a> {
25    fields: EditApplicationEmojiFields<'a>,
26    application_id: Id<ApplicationMarker>,
27    emoji_id: Id<EmojiMarker>,
28    http: &'a Client,
29}
30
31impl<'a> UpdateApplicationEmoji<'a> {
32    pub(crate) const fn new(
33        http: &'a Client,
34        application_id: Id<ApplicationMarker>,
35        emoji_id: Id<EmojiMarker>,
36        name: &'a str,
37    ) -> Self {
38        Self {
39            fields: EditApplicationEmojiFields { name },
40            application_id,
41            emoji_id,
42            http,
43        }
44    }
45}
46
47#[cfg(not(target_os = "wasi"))]
48impl IntoFuture for UpdateApplicationEmoji<'_> {
49    type Output = Result<Response<Emoji>, Error>;
50
51    type IntoFuture = ResponseFuture<Emoji>;
52
53    fn into_future(self) -> Self::IntoFuture {
54        let http = self.http;
55
56        match self.try_into_request() {
57            Ok(request) => http.request(request),
58            Err(source) => ResponseFuture::error(source),
59        }
60    }
61}
62
63impl TryIntoRequest for UpdateApplicationEmoji<'_> {
64    fn try_into_request(self) -> Result<Request, Error> {
65        let mut request = Request::builder(&Route::UpdateApplicationEmoji {
66            application_id: self.application_id.get(),
67            emoji_id: self.emoji_id.get(),
68        });
69
70        request = request.json(&self.fields);
71
72        request.build()
73    }
74}