Skip to main content

twilight_http/request/guild/
update_guild_channel_positions.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture, marker::EmptyBody};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::{
11    http::channel_position::Position,
12    id::{Id, marker::GuildMarker},
13};
14
15/// Modify the positions of the channels.
16///
17/// The minimum amount of channels to modify, is a swap between two channels.
18#[must_use = "requests must be configured and executed"]
19pub struct UpdateGuildChannelPositions<'a> {
20    guild_id: Id<GuildMarker>,
21    http: &'a Client,
22    positions: &'a [Position],
23}
24
25impl<'a> UpdateGuildChannelPositions<'a> {
26    pub(crate) const fn new(
27        http: &'a Client,
28        guild_id: Id<GuildMarker>,
29        channel_positions: &'a [Position],
30    ) -> Self {
31        Self {
32            guild_id,
33            http,
34            positions: channel_positions,
35        }
36    }
37}
38
39#[cfg(not(target_os = "wasi"))]
40impl IntoFuture for UpdateGuildChannelPositions<'_> {
41    type Output = Result<Response<EmptyBody>, Error>;
42
43    type IntoFuture = ResponseFuture<EmptyBody>;
44
45    fn into_future(self) -> Self::IntoFuture {
46        let http = self.http;
47
48        match self.try_into_request() {
49            Ok(request) => http.request(request),
50            Err(source) => ResponseFuture::error(source),
51        }
52    }
53}
54
55impl TryIntoRequest for UpdateGuildChannelPositions<'_> {
56    fn try_into_request(self) -> Result<Request, Error> {
57        Request::builder(&Route::UpdateGuildChannels {
58            guild_id: self.guild_id.get(),
59        })
60        .json(&self.positions)
61        .build()
62    }
63}