reifydb_core/interceptor/
factory.rs1use crate::{interceptor::Interceptors, interface::CommandTransaction};
5
6pub trait InterceptorFactory<CT: CommandTransaction>: Send + Sync {
8 fn create(&self) -> Interceptors<CT>;
10}
11
12pub struct StandardInterceptorFactory<CT: CommandTransaction> {
16 pub(crate) factories: Vec<Box<dyn Fn(&mut Interceptors<CT>) + Send + Sync>>,
17}
18
19impl<CT: CommandTransaction> Default for StandardInterceptorFactory<CT> {
20 fn default() -> Self {
21 Self {
22 factories: Vec::new(),
23 }
24 }
25}
26
27impl<CT: CommandTransaction> StandardInterceptorFactory<CT> {
28 pub fn add(&mut self, factory: Box<dyn Fn(&mut Interceptors<CT>) + Send + Sync>) {
30 self.factories.push(factory);
31 }
32}
33
34impl<CT: CommandTransaction> InterceptorFactory<CT> for StandardInterceptorFactory<CT> {
35 fn create(&self) -> Interceptors<CT> {
36 let mut interceptors = Interceptors::new();
37
38 for factory in &self.factories {
39 factory(&mut interceptors);
40 }
41
42 interceptors
43 }
44}