Skip to main content

twilight_http/request/scheduled_event/
get_guild_scheduled_events.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::scheduled_event::GuildScheduledEvent,
12    id::{Id, marker::GuildMarker},
13};
14
15/// Get a list of scheduled events in a guild.
16#[must_use = "requests must be configured and executed"]
17pub struct GetGuildScheduledEvents<'a> {
18    guild_id: Id<GuildMarker>,
19    http: &'a Client,
20    with_user_count: bool,
21}
22
23impl<'a> GetGuildScheduledEvents<'a> {
24    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
25        Self {
26            guild_id,
27            http,
28            with_user_count: false,
29        }
30    }
31
32    /// Set whether to include the number of subscribed users.
33    pub const fn with_user_count(mut self, with_user_count: bool) -> Self {
34        self.with_user_count = with_user_count;
35
36        self
37    }
38}
39
40#[cfg(not(target_os = "wasi"))]
41impl IntoFuture for GetGuildScheduledEvents<'_> {
42    type Output = Result<Response<ListBody<GuildScheduledEvent>>, Error>;
43
44    type IntoFuture = ResponseFuture<ListBody<GuildScheduledEvent>>;
45
46    fn into_future(self) -> Self::IntoFuture {
47        let http = self.http;
48
49        match self.try_into_request() {
50            Ok(request) => http.request(request),
51            Err(source) => ResponseFuture::error(source),
52        }
53    }
54}
55
56impl TryIntoRequest for GetGuildScheduledEvents<'_> {
57    fn try_into_request(self) -> Result<Request, Error> {
58        Ok(Request::from_route(&Route::GetGuildScheduledEvents {
59            guild_id: self.guild_id.get(),
60            with_user_count: self.with_user_count,
61        }))
62    }
63}