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