Skip to main content

twilight_http/request/channel/thread/
get_thread_member.rs

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