twilight_http/request/channel/reaction/
delete_all_reactions.rs

1use crate::{
2    client::Client,
3    error::Error,
4    request::{Request, TryIntoRequest},
5    response::{marker::EmptyBody, Response, ResponseFuture},
6    routing::Route,
7};
8use std::future::IntoFuture;
9use twilight_model::id::{
10    marker::{ChannelMarker, MessageMarker},
11    Id,
12};
13
14/// Delete all reactions by all users on a message.
15#[must_use = "requests must be configured and executed"]
16pub struct DeleteAllReactions<'a> {
17    channel_id: Id<ChannelMarker>,
18    http: &'a Client,
19    message_id: Id<MessageMarker>,
20}
21
22impl<'a> DeleteAllReactions<'a> {
23    pub(crate) const fn new(
24        http: &'a Client,
25        channel_id: Id<ChannelMarker>,
26        message_id: Id<MessageMarker>,
27    ) -> Self {
28        Self {
29            channel_id,
30            http,
31            message_id,
32        }
33    }
34}
35
36impl IntoFuture for DeleteAllReactions<'_> {
37    type Output = Result<Response<EmptyBody>, Error>;
38
39    type IntoFuture = ResponseFuture<EmptyBody>;
40
41    fn into_future(self) -> Self::IntoFuture {
42        let http = self.http;
43
44        match self.try_into_request() {
45            Ok(request) => http.request(request),
46            Err(source) => ResponseFuture::error(source),
47        }
48    }
49}
50
51impl TryIntoRequest for DeleteAllReactions<'_> {
52    fn try_into_request(self) -> Result<Request, Error> {
53        Ok(Request::from_route(&Route::DeleteMessageReactions {
54            channel_id: self.channel_id.get(),
55            message_id: self.message_id.get(),
56        }))
57    }
58}