twilight_http/request/guild/emoji/
get_emoji.rs

1use 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/// Get an emoji for a guild by the the guild's ID and emoji's ID.
18///
19/// # Examples
20///
21/// Get emoji `100` from guild `50`:
22///
23/// ```no_run
24/// use twilight_http::Client;
25/// use twilight_model::id::Id;
26///
27/// # #[tokio::main]
28/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
29/// let client = Client::new("my token".to_owned());
30///
31/// let guild_id = Id::new(50);
32/// let emoji_id = Id::new(100);
33///
34/// client.emoji(guild_id, emoji_id).await?;
35/// # Ok(()) }
36/// ```
37#[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}