twilight_http/request/application/command/
get_guild_commands.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 application::command::Command,
11 id::{
12 marker::{ApplicationMarker, GuildMarker},
13 Id,
14 },
15};
16
17#[must_use = "requests must be configured and executed"]
19pub struct GetGuildCommands<'a> {
20 application_id: Id<ApplicationMarker>,
21 guild_id: Id<GuildMarker>,
22 http: &'a Client,
23 with_localizations: Option<bool>,
24}
25
26impl<'a> GetGuildCommands<'a> {
27 pub(crate) const fn new(
28 http: &'a Client,
29 application_id: Id<ApplicationMarker>,
30 guild_id: Id<GuildMarker>,
31 ) -> Self {
32 Self {
33 application_id,
34 guild_id,
35 http,
36 with_localizations: None,
37 }
38 }
39
40 pub const fn with_localizations(mut self, with_localizations: bool) -> Self {
44 self.with_localizations = Some(with_localizations);
45
46 self
47 }
48}
49
50impl IntoFuture for GetGuildCommands<'_> {
51 type Output = Result<Response<ListBody<Command>>, Error>;
52
53 type IntoFuture = ResponseFuture<ListBody<Command>>;
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 GetGuildCommands<'_> {
66 fn try_into_request(self) -> Result<Request, Error> {
67 Ok(Request::from_route(&Route::GetGuildCommands {
68 application_id: self.application_id.get(),
69 guild_id: self.guild_id.get(),
70 with_localizations: self.with_localizations,
71 }))
72 }
73}