pub trait WebhookSender {
type Message;
type Error: Error;
// Required method
fn send(
&self,
message: &Self::Message,
) -> impl Future<Output = Result<(), Self::Error>> + Send;
// Provided method
fn send_batch<'a>(
&'a self,
messages: &'a [&'a Self::Message],
) -> impl Future<Output = Vec<Result<(), Self::Error>>> + Send + 'a
where Self: Sync,
Self::Error: Send { ... }
}Expand description
Common interface implemented by every hooksmith webhook client.
Each service crate defines its own Message and
Error types and implements this trait. Application
code can then be generic over the notification backend:
ⓘ
use hooksmith_core::WebhookSender;
async fn notify<S>(sender: &S, msg: &S::Message) -> Result<(), S::Error>
where
S: WebhookSender,
{
sender.send(msg).await
}Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn send_batch<'a>(
&'a self,
messages: &'a [&'a Self::Message],
) -> impl Future<Output = Vec<Result<(), Self::Error>>> + Send + 'a
fn send_batch<'a>( &'a self, messages: &'a [&'a Self::Message], ) -> impl Future<Output = Vec<Result<(), Self::Error>>> + Send + 'a
Send multiple messages concurrently, fanning them out with
futures::future::join_all.
Returns one Result per message in the same order as the input slice.
A failure for one message does not abort the others.
§Example
ⓘ
let results = sender.send_batch(&[&msg_a, &msg_b, &msg_c]).await;
for result in results {
result?;
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.