twilight_http/request/channel/
follow_news_channel.rs

1use crate::{
2    client::Client,
3    error::Error,
4    request::{Request, TryIntoRequest},
5    response::{Response, ResponseFuture},
6    routing::Route,
7};
8use serde::Serialize;
9use std::future::IntoFuture;
10use twilight_model::{
11    channel::FollowedChannel,
12    id::{marker::ChannelMarker, Id},
13};
14
15#[derive(Serialize)]
16struct FollowNewsChannelFields {
17    webhook_channel_id: Id<ChannelMarker>,
18}
19
20/// Follow a news channel by [`Id<ChannelMarker>`]s.
21#[must_use = "requests must be configured and executed"]
22pub struct FollowNewsChannel<'a> {
23    channel_id: Id<ChannelMarker>,
24    fields: FollowNewsChannelFields,
25    http: &'a Client,
26}
27
28impl<'a> FollowNewsChannel<'a> {
29    pub(crate) const fn new(
30        http: &'a Client,
31        channel_id: Id<ChannelMarker>,
32        webhook_channel_id: Id<ChannelMarker>,
33    ) -> Self {
34        Self {
35            channel_id,
36            http,
37            fields: FollowNewsChannelFields { webhook_channel_id },
38        }
39    }
40}
41
42impl IntoFuture for FollowNewsChannel<'_> {
43    type Output = Result<Response<FollowedChannel>, Error>;
44
45    type IntoFuture = ResponseFuture<FollowedChannel>;
46
47    fn into_future(self) -> Self::IntoFuture {
48        let http = self.http;
49
50        match self.try_into_request() {
51            Ok(request) => http.request(request),
52            Err(source) => ResponseFuture::error(source),
53        }
54    }
55}
56
57impl TryIntoRequest for FollowNewsChannel<'_> {
58    fn try_into_request(self) -> Result<Request, Error> {
59        Request::builder(&Route::FollowNewsChannel {
60            channel_id: self.channel_id.get(),
61        })
62        .json(&self.fields)
63        .build()
64    }
65}