twilight_http/request/guild/
update_guild_channel_positions.rs

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