Skip to main content

twilight_http/request/guild/emoji/
get_emojis.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture, marker::ListBody};
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::{Id, marker::GuildMarker},
13};
14
15/// Get the emojis for a guild, by the guild's id.
16///
17/// # Examples
18///
19/// Get the emojis for guild `100`:
20///
21/// ```no_run
22/// use twilight_http::Client;
23/// use twilight_model::id::Id;
24///
25/// # #[tokio::main]
26/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
27/// let client = Client::new("my token".to_owned());
28///
29/// let guild_id = Id::new(100);
30///
31/// client.emojis(guild_id).await?;
32/// # Ok(()) }
33/// ```
34#[must_use = "requests must be configured and executed"]
35pub struct GetEmojis<'a> {
36    guild_id: Id<GuildMarker>,
37    http: &'a Client,
38}
39
40impl<'a> GetEmojis<'a> {
41    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
42        Self { guild_id, http }
43    }
44}
45
46#[cfg(not(target_os = "wasi"))]
47impl IntoFuture for GetEmojis<'_> {
48    type Output = Result<Response<ListBody<Emoji>>, Error>;
49
50    type IntoFuture = ResponseFuture<ListBody<Emoji>>;
51
52    fn into_future(self) -> Self::IntoFuture {
53        let http = self.http;
54
55        match self.try_into_request() {
56            Ok(request) => http.request(request),
57            Err(source) => ResponseFuture::error(source),
58        }
59    }
60}
61
62impl TryIntoRequest for GetEmojis<'_> {
63    fn try_into_request(self) -> Result<Request, Error> {
64        Ok(Request::from_route(&Route::GetEmojis {
65            guild_id: self.guild_id.get(),
66        }))
67    }
68}