twilight_http/request/channel/thread/
leave_thread.rs1use 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::id::{marker::ChannelMarker, Id};
10
11#[must_use = "requests must be configured and executed"]
15pub struct LeaveThread<'a> {
16 channel_id: Id<ChannelMarker>,
17 http: &'a Client,
18}
19
20impl<'a> LeaveThread<'a> {
21 pub(crate) const fn new(http: &'a Client, channel_id: Id<ChannelMarker>) -> Self {
22 Self { channel_id, http }
23 }
24}
25
26impl IntoFuture for LeaveThread<'_> {
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 LeaveThread<'_> {
42 fn try_into_request(self) -> Result<Request, Error> {
43 Ok(Request::from_route(&Route::LeaveThread {
44 channel_id: self.channel_id.get(),
45 }))
46 }
47}