use crate::{Event, World};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub enum HookOutcome {
Allow,
Deny { reason: String },
Mutate(serde_json::Value),
Inject(String),
}
pub trait Hook: Send + Sync + 'static {
fn name(&self) -> &str;
fn matches(&self, ev: &Event<'_>) -> bool;
fn fire(&self, ev: &Event<'_>, world: &mut World) -> HookOutcome;
}
pub struct HookEntry {
pub factory: fn() -> Arc<dyn Hook>,
}
inventory::collect!(HookEntry);
pub fn iter_macro_hooks() -> impl Iterator<Item = Arc<dyn Hook>> {
inventory::iter::<HookEntry>().map(|e| (e.factory)())
}