twilight_http/request/guild/
get_guild_channels.rs1use crate::{
2 client::Client,
3 error::Error,
4 request::{Request, TryIntoRequest},
5 response::{Response, ResponseFuture, marker::ListBody},
6 routing::Route,
7};
8use std::future::IntoFuture;
9use twilight_model::{
10 channel::Channel,
11 id::{Id, marker::GuildMarker},
12};
13
14#[must_use = "requests must be configured and executed"]
22pub struct GetGuildChannels<'a> {
23 guild_id: Id<GuildMarker>,
24 http: &'a Client,
25}
26
27impl<'a> GetGuildChannels<'a> {
28 pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
29 Self { guild_id, http }
30 }
31}
32
33impl IntoFuture for GetGuildChannels<'_> {
34 type Output = Result<Response<ListBody<Channel>>, Error>;
35
36 type IntoFuture = ResponseFuture<ListBody<Channel>>;
37
38 fn into_future(self) -> Self::IntoFuture {
39 let http = self.http;
40
41 match self.try_into_request() {
42 Ok(request) => http.request(request),
43 Err(source) => ResponseFuture::error(source),
44 }
45 }
46}
47
48impl TryIntoRequest for GetGuildChannels<'_> {
49 fn try_into_request(self) -> Result<Request, Error> {
50 Ok(Request::from_route(&Route::GetChannels {
51 guild_id: self.guild_id.get(),
52 }))
53 }
54}