twilight_http/request/guild/emoji/
get_emoji.rs1use 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 guild::Emoji,
11 id::{
12 marker::{EmojiMarker, GuildMarker},
13 Id,
14 },
15};
16
17#[must_use = "requests must be configured and executed"]
38pub struct GetEmoji<'a> {
39 emoji_id: Id<EmojiMarker>,
40 guild_id: Id<GuildMarker>,
41 http: &'a Client,
42}
43
44impl<'a> GetEmoji<'a> {
45 pub(crate) const fn new(
46 http: &'a Client,
47 guild_id: Id<GuildMarker>,
48 emoji_id: Id<EmojiMarker>,
49 ) -> Self {
50 Self {
51 emoji_id,
52 guild_id,
53 http,
54 }
55 }
56}
57
58impl IntoFuture for GetEmoji<'_> {
59 type Output = Result<Response<Emoji>, Error>;
60
61 type IntoFuture = ResponseFuture<Emoji>;
62
63 fn into_future(self) -> Self::IntoFuture {
64 let http = self.http;
65
66 match self.try_into_request() {
67 Ok(request) => http.request(request),
68 Err(source) => ResponseFuture::error(source),
69 }
70 }
71}
72
73impl TryIntoRequest for GetEmoji<'_> {
74 fn try_into_request(self) -> Result<Request, Error> {
75 Ok(Request::from_route(&Route::GetEmoji {
76 emoji_id: self.emoji_id.get(),
77 guild_id: self.guild_id.get(),
78 }))
79 }
80}