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