Skip to main content

hooksmith_core/
sender.rs

1use std::future::Future;
2
3/// Common interface implemented by every hooksmith webhook client.
4///
5/// Each service crate defines its own [`Message`](WebhookSender::Message) and
6/// [`Error`](WebhookSender::Error) types and implements this trait.  Application
7/// code can then be generic over the notification backend:
8///
9/// ```rust,ignore
10/// use hooksmith_core::WebhookSender;
11///
12/// async fn notify<S>(sender: &S, msg: &S::Message) -> Result<(), S::Error>
13/// where
14///     S: WebhookSender,
15/// {
16///     sender.send(msg).await
17/// }
18/// ```
19pub trait WebhookSender {
20    /// The message type accepted by this sender.
21    type Message;
22
23    /// The error type returned on failure.
24    type Error: std::error::Error;
25
26    /// Send a single message to the configured webhook endpoint.
27    fn send(
28        &self,
29        message: &Self::Message,
30    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
31}