1use crate::{Event, World};
2use serde::{Deserialize, Serialize};
3use std::sync::Arc;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7#[non_exhaustive]
8pub enum HookOutcome {
9 Allow,
11 Deny { reason: String },
13 Mutate(serde_json::Value),
15 Inject(String),
17}
18
19pub trait Hook: Send + Sync + 'static {
20 fn name(&self) -> &str;
21 fn matches(&self, ev: &Event<'_>) -> bool;
22 fn fire(&self, ev: &Event<'_>, world: &mut World) -> HookOutcome;
23}
24
25pub struct HookEntry {
27 pub factory: fn() -> Arc<dyn Hook>,
28}
29
30inventory::collect!(HookEntry);
31
32pub fn iter_macro_hooks() -> impl Iterator<Item = Arc<dyn Hook>> {
34 inventory::iter::<HookEntry>().map(|e| (e.factory)())
35}