reifydb_core/interceptor/
chain.rs1use std::{marker::PhantomData, sync::Arc};
5
6use crate::interface::CommandTransaction;
7
8pub struct InterceptorChain<T: CommandTransaction, I: ?Sized> {
10 pub(crate) interceptors: Vec<Arc<I>>,
11 _phantom: PhantomData<T>,
12}
13
14impl<T: CommandTransaction, I: ?Sized> InterceptorChain<T, I> {
15 pub fn new() -> Self {
16 Self {
17 interceptors: Vec::new(),
18 _phantom: PhantomData,
19 }
20 }
21
22 pub fn add(&mut self, interceptor: Arc<I>) {
23 self.interceptors.push(interceptor);
24 }
25
26 pub fn is_empty(&self) -> bool {
27 self.interceptors.is_empty()
28 }
29
30 pub fn len(&self) -> usize {
31 self.interceptors.len()
32 }
33
34 pub fn clear(&mut self) {
35 self.interceptors.clear()
36 }
37}
38
39impl<T: CommandTransaction, I: ?Sized> Default for InterceptorChain<T, I> {
40 fn default() -> Self {
41 Self::new()
42 }
43}
44
45impl<T: CommandTransaction, I: ?Sized> Clone for InterceptorChain<T, I> {
46 fn clone(&self) -> Self {
47 Self {
48 interceptors: self.interceptors.clone(),
49 _phantom: PhantomData,
50 }
51 }
52}