twilight_http/request/channel/thread/
add_thread_member.rs1#[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::{
11 Id,
12 marker::{ChannelMarker, UserMarker},
13};
14
15#[must_use = "requests must be configured and executed"]
20pub struct AddThreadMember<'a> {
21 channel_id: Id<ChannelMarker>,
22 http: &'a Client,
23 user_id: Id<UserMarker>,
24}
25
26impl<'a> AddThreadMember<'a> {
27 pub(crate) const fn new(
28 http: &'a Client,
29 channel_id: Id<ChannelMarker>,
30 user_id: Id<UserMarker>,
31 ) -> Self {
32 Self {
33 channel_id,
34 http,
35 user_id,
36 }
37 }
38}
39
40#[cfg(not(target_os = "wasi"))]
41impl IntoFuture for AddThreadMember<'_> {
42 type Output = Result<Response<EmptyBody>, Error>;
43
44 type IntoFuture = ResponseFuture<EmptyBody>;
45
46 fn into_future(self) -> Self::IntoFuture {
47 let http = self.http;
48
49 match self.try_into_request() {
50 Ok(request) => http.request(request),
51 Err(source) => ResponseFuture::error(source),
52 }
53 }
54}
55
56impl TryIntoRequest for AddThreadMember<'_> {
57 fn try_into_request(self) -> Result<Request, Error> {
58 Ok(Request::from_route(&Route::AddThreadMember {
59 channel_id: self.channel_id.get(),
60 user_id: self.user_id.get(),
61 }))
62 }
63}