1use async_trait::async_trait;
2use rspack_error::Result;
3use rustc_hash::FxHashSet;
4
5#[async_trait]
6pub trait Interceptor<H: Hook> {
7 async fn call(&self, _hook: &H) -> Result<Vec<<H as Hook>::Tap>> {
8 unreachable!("Interceptor::call should only used in async hook")
9 }
10
11 fn call_blocking(&self, _hook: &H) -> Result<Vec<<H as Hook>::Tap>> {
12 unreachable!("Interceptor::call_blocking should only used in sync hook")
13 }
14}
15
16pub trait Hook {
17 type Tap;
18
19 fn used_stages(&self) -> FxHashSet<i32>;
20
21 fn intercept(&mut self, interceptor: impl Interceptor<Self> + Send + Sync + 'static)
22 where
23 Self: Sized;
24}
25
26#[doc(hidden)]
31pub mod __macro_helper {
32 pub use async_trait::async_trait;
33 pub use rspack_error::Result;
34 pub use rustc_hash::FxHashSet;
35 pub use tracing;
36}
37
38pub use rspack_macros::{define_hook, plugin, plugin_hook};