Skip to main content

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