reifydb_core/interceptor/
builder.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use crate::{
5	interceptor::{Interceptors, factory::StandardInterceptorFactory},
6	interface::CommandTransaction,
7};
8
9/// Builder for configuring interceptors using factory functions
10/// This allows building a Send+Sync factory that creates non-Send/Sync
11/// interceptors
12pub struct StandardInterceptorBuilder<CT: CommandTransaction> {
13	factory: StandardInterceptorFactory<CT>,
14}
15
16impl<CT: CommandTransaction> Default for StandardInterceptorBuilder<CT> {
17	fn default() -> Self {
18		Self::new()
19	}
20}
21
22impl<CT: CommandTransaction> StandardInterceptorBuilder<CT> {
23	pub fn new() -> Self {
24		Self {
25			factory: StandardInterceptorFactory::default(),
26		}
27	}
28	pub fn add_factory<F>(mut self, factory: F) -> Self
29	where
30		F: Fn(&mut Interceptors<CT>) + Send + Sync + 'static,
31	{
32		self.factory.add(Box::new(factory));
33		self
34	}
35
36	pub fn build(self) -> StandardInterceptorFactory<CT> {
37		self.factory
38	}
39}