Skip to main content

twilight_http/request/scheduled_event/
get_guild_scheduled_event.rs

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