twilight_http/request/guild/emoji/
get_emojis.rs

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