twilight_http/request/application/emoji/
update_emoji.rs

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