twilight_http/request/channel/thread/
get_public_archived_threads.rs1#[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::ThreadsListing,
12 id::{Id, marker::ChannelMarker},
13};
14
15#[must_use = "requests must be configured and executed"]
32pub struct GetPublicArchivedThreads<'a> {
33 before: Option<&'a str>,
34 channel_id: Id<ChannelMarker>,
35 http: &'a Client,
36 limit: Option<u64>,
37}
38
39impl<'a> GetPublicArchivedThreads<'a> {
40 pub(crate) const fn new(http: &'a Client, channel_id: Id<ChannelMarker>) -> Self {
41 Self {
42 before: None,
43 channel_id,
44 http,
45 limit: None,
46 }
47 }
48
49 pub const fn before(mut self, before: &'a str) -> Self {
51 self.before = Some(before);
52
53 self
54 }
55
56 pub const fn limit(mut self, limit: u64) -> Self {
58 self.limit = Some(limit);
59
60 self
61 }
62}
63
64#[cfg(not(target_os = "wasi"))]
65impl IntoFuture for GetPublicArchivedThreads<'_> {
66 type Output = Result<Response<ThreadsListing>, Error>;
67
68 type IntoFuture = ResponseFuture<ThreadsListing>;
69
70 fn into_future(self) -> Self::IntoFuture {
71 let http = self.http;
72
73 match self.try_into_request() {
74 Ok(request) => http.request(request),
75 Err(source) => ResponseFuture::error(source),
76 }
77 }
78}
79
80impl TryIntoRequest for GetPublicArchivedThreads<'_> {
81 fn try_into_request(self) -> Result<Request, Error> {
82 Ok(Request::from_route(&Route::GetPublicArchivedThreads {
83 before: self.before,
84 channel_id: self.channel_id.get(),
85 limit: self.limit,
86 }))
87 }
88}