twilight_http/request/channel/
get_channel.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::Channel,
12 id::{Id, marker::ChannelMarker},
13};
14
15#[must_use = "requests must be configured and executed"]
35pub struct GetChannel<'a> {
36 channel_id: Id<ChannelMarker>,
37 http: &'a Client,
38}
39
40impl<'a> GetChannel<'a> {
41 pub(crate) const fn new(http: &'a Client, channel_id: Id<ChannelMarker>) -> Self {
42 Self { channel_id, http }
43 }
44}
45
46#[cfg(not(target_os = "wasi"))]
47impl IntoFuture for GetChannel<'_> {
48 type Output = Result<Response<Channel>, Error>;
49
50 type IntoFuture = ResponseFuture<Channel>;
51
52 fn into_future(self) -> Self::IntoFuture {
53 let http = self.http;
54
55 match self.try_into_request() {
56 Ok(request) => http.request(request),
57 Err(source) => ResponseFuture::error(source),
58 }
59 }
60}
61
62impl TryIntoRequest for GetChannel<'_> {
63 fn try_into_request(self) -> Result<Request, Error> {
64 Ok(Request::from_route(&Route::GetChannel {
65 channel_id: self.channel_id.get(),
66 }))
67 }
68}