use std::sync::Arc;
use super::super::{
context::HandlerContext,
event::{DynEvent, EventResult},
subscription::SubscriptionId,
};
pub(super) type HandlerFn = Arc<dyn Fn(&DynEvent) -> EventResult + Send + Sync>;
pub(super) type ContextHandlerFn =
Arc<dyn for<'a> Fn(&DynEvent, &mut HandlerContext<'a>) -> EventResult + Send + Sync>;
pub(super) enum HandlerType {
Simple(HandlerFn),
WithContext(ContextHandlerFn),
}
impl Clone for HandlerType {
fn clone(&self) -> Self {
match self {
Self::Simple(h) => Self::Simple(h.clone()),
Self::WithContext(h) => Self::WithContext(h.clone()),
}
}
}
pub(super) struct RegisteredHandler {
pub id: SubscriptionId,
pub priority: u32,
pub handler: HandlerType,
}
impl Clone for RegisteredHandler {
fn clone(&self) -> Self {
Self {
id: self.id,
priority: self.priority,
handler: self.handler.clone(),
}
}
}