twilight_http/request/application/command/
set_global_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::{marker::ApplicationMarker, Id},
12};
13
14#[must_use = "requests must be configured and executed"]
25pub struct SetGlobalCommands<'a> {
26 commands: &'a [Command],
27 application_id: Id<ApplicationMarker>,
28 http: &'a Client,
29}
30
31impl<'a> SetGlobalCommands<'a> {
32 pub(crate) const fn new(
33 http: &'a Client,
34 application_id: Id<ApplicationMarker>,
35 commands: &'a [Command],
36 ) -> Self {
37 Self {
38 commands,
39 application_id,
40 http,
41 }
42 }
43}
44
45impl IntoFuture for SetGlobalCommands<'_> {
46 type Output = Result<Response<ListBody<Command>>, Error>;
47
48 type IntoFuture = ResponseFuture<ListBody<Command>>;
49
50 fn into_future(self) -> Self::IntoFuture {
51 let http = self.http;
52
53 match self.try_into_request() {
54 Ok(request) => http.request(request),
55 Err(source) => ResponseFuture::error(source),
56 }
57 }
58}
59
60impl TryIntoRequest for SetGlobalCommands<'_> {
61 fn try_into_request(self) -> Result<Request, Error> {
62 Request::builder(&Route::SetGlobalCommands {
63 application_id: self.application_id.get(),
64 })
65 .json(&self.commands)
66 .build()
67 }
68}