tulpje_framework/handler/
event_handler.rsuse std::hash::{Hash, Hasher};
use std::{future::Future, pin::Pin};
use twilight_gateway::EventType;
use super::super::context::EventContext;
use crate::Error;
pub(crate) type EventFunc<T> =
fn(EventContext<T>) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
#[derive(Clone)]
pub struct EventHandler<T: Clone + Send + Sync> {
pub module: String,
pub uuid: String,
pub event: EventType,
pub func: EventFunc<T>,
}
impl<T: Clone + Send + Sync> EventHandler<T> {
pub async fn run(&self, ctx: EventContext<T>) -> Result<(), Error> {
(self.func)(ctx).await
}
}
impl<T: Clone + Send + Sync> Hash for EventHandler<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.uuid.hash(state);
self.event.hash(state);
}
}
impl<T: Clone + Send + Sync> PartialEq for EventHandler<T> {
fn eq(&self, other: &Self) -> bool {
self.event == other.event && self.uuid == other.uuid
}
}
impl<T: Clone + Send + Sync> Eq for EventHandler<T> {}