twilight_http/request/guild/
get_active_threads.rs

1use 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::GuildMarker, Id},
12};
13
14/// Returns all active threads in the guild.
15///
16/// Includes public and private threads. Threads are ordered by their ID in
17/// descending order.
18#[must_use = "requests must be configured and executed"]
19pub struct GetActiveThreads<'a> {
20    guild_id: Id<GuildMarker>,
21    http: &'a Client,
22}
23
24impl<'a> GetActiveThreads<'a> {
25    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
26        Self { guild_id, http }
27    }
28}
29
30impl IntoFuture for GetActiveThreads<'_> {
31    type Output = Result<Response<ThreadsListing>, Error>;
32
33    type IntoFuture = ResponseFuture<ThreadsListing>;
34
35    fn into_future(self) -> Self::IntoFuture {
36        let http = self.http;
37
38        match self.try_into_request() {
39            Ok(request) => http.request(request),
40            Err(source) => ResponseFuture::error(source),
41        }
42    }
43}
44
45impl TryIntoRequest for GetActiveThreads<'_> {
46    fn try_into_request(self) -> Result<Request, Error> {
47        Ok(Request::from_route(&Route::GetActiveThreads {
48            guild_id: self.guild_id.get(),
49        }))
50    }
51}