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