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