hookburn-core 0.2.2

Shared HTTP client and WebhookSender trait for the Hookburn crates
Documentation
// crates/hookburn-core/src/sender.rs
use async_trait::async_trait;

/// A unified interface for sending messages to webhook services.
///
/// This trait is implemented by each service crate (Discord, Slack, etc.)
/// to provide a consistent way to send webhook messages.
///
/// # Examples
///
/// Basic usage with a Discord client:
///
/// ```rust,no_run
/// use hookburn_core::WebhookSender;
///
/// async fn send_message<S>(client: &S, msg: &S::Message) -> Result<(), S::Error>
/// where
///     S: WebhookSender,
/// {
///     client.send(msg).await
/// }
/// ```
///
/// Using with trait objects:
///
/// ```rust,no_run
/// use hookburn_core::{WebhookSender, BoxedWebhookSender, GenericMessage, CoreError};
///
/// fn create_sender() -> BoxedWebhookSender {
///     // Returns a boxed sender that accepts GenericMessage
///     # unimplemented!()
/// }
/// ```
#[async_trait]
pub trait WebhookSender: Send + Sync {
    /// The type of message this sender accepts (e.g., `WebhookMessage` for Discord).
    type Message: Send + Sync;

    /// The error type returned when sending fails (e.g., `WebhookError` for Discord).
    type Error: std::error::Error + Send + Sync;

    /// Send a single message to the configured webhook endpoint.
    ///
    /// # Errors
    ///
    /// Returns `Self::Error` if the message could not be sent. Possible reasons include:
    /// - Network failures
    /// - Rate limiting (HTTP 429)
    /// - Invalid message structure
    /// - Service API errors (HTTP 4xx or 5xx)
    ///
    /// # Example
    ///
    /// ```rust,no_run
    /// # use hookburn_core::WebhookSender;
    /// # async fn example<S>(client: &S, msg: &S::Message) -> Result<(), S::Error>
    /// # where S: WebhookSender {
    /// client.send(msg).await?;
    /// # Ok(())
    /// # }
    /// ```
    async fn send(&self, message: &Self::Message) -> Result<(), Self::Error>;
}