Skip to main content

twilight_http/request/channel/thread/
join_thread.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::id::{Id, marker::ChannelMarker};
11
12/// Add the current user to a thread.
13#[must_use = "requests must be configured and executed"]
14pub struct JoinThread<'a> {
15    channel_id: Id<ChannelMarker>,
16    http: &'a Client,
17}
18
19impl<'a> JoinThread<'a> {
20    pub(crate) const fn new(http: &'a Client, channel_id: Id<ChannelMarker>) -> Self {
21        Self { channel_id, http }
22    }
23}
24
25#[cfg(not(target_os = "wasi"))]
26impl IntoFuture for JoinThread<'_> {
27    type Output = Result<Response<EmptyBody>, Error>;
28
29    type IntoFuture = ResponseFuture<EmptyBody>;
30
31    fn into_future(self) -> Self::IntoFuture {
32        let http = self.http;
33
34        match self.try_into_request() {
35            Ok(request) => http.request(request),
36            Err(source) => ResponseFuture::error(source),
37        }
38    }
39}
40
41impl TryIntoRequest for JoinThread<'_> {
42    fn try_into_request(self) -> Result<Request, Error> {
43        Ok(Request::from_route(&Route::JoinThread {
44            channel_id: self.channel_id.get(),
45        }))
46    }
47}