twilight_http/request/channel/message/
get_message.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::Message,
11    id::{
12        marker::{ChannelMarker, MessageMarker},
13        Id,
14    },
15};
16
17/// Get a message by [`Id<ChannelMarker>`] and [`Id<MessageMarker>`].
18#[must_use = "requests must be configured and executed"]
19pub struct GetMessage<'a> {
20    channel_id: Id<ChannelMarker>,
21    http: &'a Client,
22    message_id: Id<MessageMarker>,
23}
24
25impl<'a> GetMessage<'a> {
26    pub(crate) const fn new(
27        http: &'a Client,
28        channel_id: Id<ChannelMarker>,
29        message_id: Id<MessageMarker>,
30    ) -> Self {
31        Self {
32            channel_id,
33            http,
34            message_id,
35        }
36    }
37}
38
39impl IntoFuture for GetMessage<'_> {
40    type Output = Result<Response<Message>, Error>;
41
42    type IntoFuture = ResponseFuture<Message>;
43
44    fn into_future(self) -> Self::IntoFuture {
45        let http = self.http;
46
47        match self.try_into_request() {
48            Ok(request) => http.request(request),
49            Err(source) => ResponseFuture::error(source),
50        }
51    }
52}
53
54impl TryIntoRequest for GetMessage<'_> {
55    fn try_into_request(self) -> Result<Request, Error> {
56        Ok(Request::from_route(&Route::GetMessage {
57            channel_id: self.channel_id.get(),
58            message_id: self.message_id.get(),
59        }))
60    }
61}