twilight_http/request/channel/thread/
get_public_archived_threads.rs1use crate::{
2 client::Client,
3 error::Error,
4 request::{Request, TryIntoRequest},
5 response::{Response, ResponseFuture},
6 routing::Route,
7};
8use std::future::IntoFuture;
9use twilight_model::{
10 channel::thread::ThreadsListing,
11 id::{marker::ChannelMarker, Id},
12};
13
14#[must_use = "requests must be configured and executed"]
31pub struct GetPublicArchivedThreads<'a> {
32 before: Option<&'a str>,
33 channel_id: Id<ChannelMarker>,
34 http: &'a Client,
35 limit: Option<u64>,
36}
37
38impl<'a> GetPublicArchivedThreads<'a> {
39 pub(crate) const fn new(http: &'a Client, channel_id: Id<ChannelMarker>) -> Self {
40 Self {
41 before: None,
42 channel_id,
43 http,
44 limit: None,
45 }
46 }
47
48 pub const fn before(mut self, before: &'a str) -> Self {
50 self.before = Some(before);
51
52 self
53 }
54
55 pub const fn limit(mut self, limit: u64) -> Self {
57 self.limit = Some(limit);
58
59 self
60 }
61}
62
63impl IntoFuture for GetPublicArchivedThreads<'_> {
64 type Output = Result<Response<ThreadsListing>, Error>;
65
66 type IntoFuture = ResponseFuture<ThreadsListing>;
67
68 fn into_future(self) -> Self::IntoFuture {
69 let http = self.http;
70
71 match self.try_into_request() {
72 Ok(request) => http.request(request),
73 Err(source) => ResponseFuture::error(source),
74 }
75 }
76}
77
78impl TryIntoRequest for GetPublicArchivedThreads<'_> {
79 fn try_into_request(self) -> Result<Request, Error> {
80 Ok(Request::from_route(&Route::GetPublicArchivedThreads {
81 before: self.before,
82 channel_id: self.channel_id.get(),
83 limit: self.limit,
84 }))
85 }
86}