pretix_webhook/
handler.rs1use std::{fmt::Display, future::Future};
2
3use pretix_webhook_events::WebhookEvent;
4
5pub trait WebhookHandler: Send + Sync + 'static {
7 type Error: Display + Send + Sync + 'static;
9
10 fn handle(&self, event: WebhookEvent) -> impl Future<Output = Result<(), Self::Error>> + Send;
17}
18
19impl<F, Fut, E> WebhookHandler for F
20where
21 F: Fn(WebhookEvent) -> Fut + Send + Sync + 'static,
22 Fut: Future<Output = Result<(), E>> + Send,
23 E: Display + Send + Sync + 'static,
24{
25 type Error = E;
26
27 fn handle(&self, event: WebhookEvent) -> impl Future<Output = Result<(), Self::Error>> + Send {
28 (self)(event)
29 }
30}