twilight_http/request/channel/webhook/
execute_webhook_and_wait.rs1use super::ExecuteWebhook;
2use crate::{
3    client::Client,
4    error::Error,
5    request::{Request, TryIntoRequest},
6    response::{Response, ResponseFuture},
7};
8use std::future::IntoFuture;
9use twilight_model::channel::Message;
10
11#[must_use = "requests must be configured and executed"]
37pub struct ExecuteWebhookAndWait<'a> {
38    http: &'a Client,
39    inner: ExecuteWebhook<'a>,
40}
41
42impl<'a> ExecuteWebhookAndWait<'a> {
43    pub(crate) const fn new(http: &'a Client, inner: ExecuteWebhook<'a>) -> Self {
44        Self { http, inner }
45    }
46}
47
48impl IntoFuture for ExecuteWebhookAndWait<'_> {
49    type Output = Result<Response<Message>, Error>;
50
51    type IntoFuture = ResponseFuture<Message>;
52
53    fn into_future(self) -> Self::IntoFuture {
54        let http = self.http;
55
56        match self.try_into_request() {
57            Ok(request) => http.request(request),
58            Err(source) => ResponseFuture::error(source),
59        }
60    }
61}
62
63impl TryIntoRequest for ExecuteWebhookAndWait<'_> {
64    fn try_into_request(self) -> Result<Request, Error> {
65        self.inner.try_into_request()
66    }
67}