twilight_http/request/application/command/
get_guild_commands.rs1#[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 application::command::Command,
12 id::{
13 Id,
14 marker::{ApplicationMarker, GuildMarker},
15 },
16};
17
18#[must_use = "requests must be configured and executed"]
20pub struct GetGuildCommands<'a> {
21 application_id: Id<ApplicationMarker>,
22 guild_id: Id<GuildMarker>,
23 http: &'a Client,
24 with_localizations: Option<bool>,
25}
26
27impl<'a> GetGuildCommands<'a> {
28 pub(crate) const fn new(
29 http: &'a Client,
30 application_id: Id<ApplicationMarker>,
31 guild_id: Id<GuildMarker>,
32 ) -> Self {
33 Self {
34 application_id,
35 guild_id,
36 http,
37 with_localizations: None,
38 }
39 }
40
41 pub const fn with_localizations(mut self, with_localizations: bool) -> Self {
45 self.with_localizations = Some(with_localizations);
46
47 self
48 }
49}
50
51#[cfg(not(target_os = "wasi"))]
52impl IntoFuture for GetGuildCommands<'_> {
53 type Output = Result<Response<ListBody<Command>>, Error>;
54
55 type IntoFuture = ResponseFuture<ListBody<Command>>;
56
57 fn into_future(self) -> Self::IntoFuture {
58 let http = self.http;
59
60 match self.try_into_request() {
61 Ok(request) => http.request(request),
62 Err(source) => ResponseFuture::error(source),
63 }
64 }
65}
66
67impl TryIntoRequest for GetGuildCommands<'_> {
68 fn try_into_request(self) -> Result<Request, Error> {
69 Ok(Request::from_route(&Route::GetGuildCommands {
70 application_id: self.application_id.get(),
71 guild_id: self.guild_id.get(),
72 with_localizations: self.with_localizations,
73 }))
74 }
75}