reifydb_transaction/interceptor/
ringbuffer.rs1use reifydb_core::interface::catalog::ringbuffer::RingBuffer;
5use reifydb_type::Result;
6
7use crate::interceptor::chain::InterceptorChain;
8
9pub struct RingBufferPostCreateContext<'a> {
10 pub post: &'a RingBuffer,
11}
12
13impl<'a> RingBufferPostCreateContext<'a> {
14 pub fn new(post: &'a RingBuffer) -> Self {
15 Self {
16 post,
17 }
18 }
19}
20
21pub trait RingBufferPostCreateInterceptor: Send + Sync {
22 fn intercept<'a>(&self, ctx: &mut RingBufferPostCreateContext<'a>) -> Result<()>;
23}
24
25impl InterceptorChain<dyn RingBufferPostCreateInterceptor + Send + Sync> {
26 pub fn execute(&self, mut ctx: RingBufferPostCreateContext) -> Result<()> {
27 for interceptor in &self.interceptors {
28 interceptor.intercept(&mut ctx)?;
29 }
30 Ok(())
31 }
32}
33
34pub struct ClosureRingBufferPostCreateInterceptor<F>
35where
36 F: for<'a> Fn(&mut RingBufferPostCreateContext<'a>) -> Result<()> + Send + Sync,
37{
38 closure: F,
39}
40
41impl<F> ClosureRingBufferPostCreateInterceptor<F>
42where
43 F: for<'a> Fn(&mut RingBufferPostCreateContext<'a>) -> Result<()> + Send + Sync,
44{
45 pub fn new(closure: F) -> Self {
46 Self {
47 closure,
48 }
49 }
50}
51
52impl<F> Clone for ClosureRingBufferPostCreateInterceptor<F>
53where
54 F: for<'a> Fn(&mut RingBufferPostCreateContext<'a>) -> Result<()> + Send + Sync + Clone,
55{
56 fn clone(&self) -> Self {
57 Self {
58 closure: self.closure.clone(),
59 }
60 }
61}
62
63impl<F> RingBufferPostCreateInterceptor for ClosureRingBufferPostCreateInterceptor<F>
64where
65 F: for<'a> Fn(&mut RingBufferPostCreateContext<'a>) -> Result<()> + Send + Sync,
66{
67 fn intercept<'a>(&self, ctx: &mut RingBufferPostCreateContext<'a>) -> Result<()> {
68 (self.closure)(ctx)
69 }
70}
71
72pub fn ringbuffer_post_create<F>(f: F) -> ClosureRingBufferPostCreateInterceptor<F>
73where
74 F: for<'a> Fn(&mut RingBufferPostCreateContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
75{
76 ClosureRingBufferPostCreateInterceptor::new(f)
77}
78
79pub struct RingBufferPreUpdateContext<'a> {
80 pub pre: &'a RingBuffer,
81}
82
83impl<'a> RingBufferPreUpdateContext<'a> {
84 pub fn new(pre: &'a RingBuffer) -> Self {
85 Self {
86 pre,
87 }
88 }
89}
90
91pub trait RingBufferPreUpdateInterceptor: Send + Sync {
92 fn intercept<'a>(&self, ctx: &mut RingBufferPreUpdateContext<'a>) -> Result<()>;
93}
94
95impl InterceptorChain<dyn RingBufferPreUpdateInterceptor + Send + Sync> {
96 pub fn execute(&self, mut ctx: RingBufferPreUpdateContext) -> Result<()> {
97 for interceptor in &self.interceptors {
98 interceptor.intercept(&mut ctx)?;
99 }
100 Ok(())
101 }
102}
103
104pub struct ClosureRingBufferPreUpdateInterceptor<F>
105where
106 F: for<'a> Fn(&mut RingBufferPreUpdateContext<'a>) -> Result<()> + Send + Sync,
107{
108 closure: F,
109}
110
111impl<F> ClosureRingBufferPreUpdateInterceptor<F>
112where
113 F: for<'a> Fn(&mut RingBufferPreUpdateContext<'a>) -> Result<()> + Send + Sync,
114{
115 pub fn new(closure: F) -> Self {
116 Self {
117 closure,
118 }
119 }
120}
121
122impl<F> Clone for ClosureRingBufferPreUpdateInterceptor<F>
123where
124 F: for<'a> Fn(&mut RingBufferPreUpdateContext<'a>) -> Result<()> + Send + Sync + Clone,
125{
126 fn clone(&self) -> Self {
127 Self {
128 closure: self.closure.clone(),
129 }
130 }
131}
132
133impl<F> RingBufferPreUpdateInterceptor for ClosureRingBufferPreUpdateInterceptor<F>
134where
135 F: for<'a> Fn(&mut RingBufferPreUpdateContext<'a>) -> Result<()> + Send + Sync,
136{
137 fn intercept<'a>(&self, ctx: &mut RingBufferPreUpdateContext<'a>) -> Result<()> {
138 (self.closure)(ctx)
139 }
140}
141
142pub fn ringbuffer_pre_update<F>(f: F) -> ClosureRingBufferPreUpdateInterceptor<F>
143where
144 F: for<'a> Fn(&mut RingBufferPreUpdateContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
145{
146 ClosureRingBufferPreUpdateInterceptor::new(f)
147}
148
149pub struct RingBufferPostUpdateContext<'a> {
150 pub pre: &'a RingBuffer,
151 pub post: &'a RingBuffer,
152}
153
154impl<'a> RingBufferPostUpdateContext<'a> {
155 pub fn new(pre: &'a RingBuffer, post: &'a RingBuffer) -> Self {
156 Self {
157 pre,
158 post,
159 }
160 }
161}
162
163pub trait RingBufferPostUpdateInterceptor: Send + Sync {
164 fn intercept<'a>(&self, ctx: &mut RingBufferPostUpdateContext<'a>) -> Result<()>;
165}
166
167impl InterceptorChain<dyn RingBufferPostUpdateInterceptor + Send + Sync> {
168 pub fn execute(&self, mut ctx: RingBufferPostUpdateContext) -> Result<()> {
169 for interceptor in &self.interceptors {
170 interceptor.intercept(&mut ctx)?;
171 }
172 Ok(())
173 }
174}
175
176pub struct ClosureRingBufferPostUpdateInterceptor<F>
177where
178 F: for<'a> Fn(&mut RingBufferPostUpdateContext<'a>) -> Result<()> + Send + Sync,
179{
180 closure: F,
181}
182
183impl<F> ClosureRingBufferPostUpdateInterceptor<F>
184where
185 F: for<'a> Fn(&mut RingBufferPostUpdateContext<'a>) -> Result<()> + Send + Sync,
186{
187 pub fn new(closure: F) -> Self {
188 Self {
189 closure,
190 }
191 }
192}
193
194impl<F> Clone for ClosureRingBufferPostUpdateInterceptor<F>
195where
196 F: for<'a> Fn(&mut RingBufferPostUpdateContext<'a>) -> Result<()> + Send + Sync + Clone,
197{
198 fn clone(&self) -> Self {
199 Self {
200 closure: self.closure.clone(),
201 }
202 }
203}
204
205impl<F> RingBufferPostUpdateInterceptor for ClosureRingBufferPostUpdateInterceptor<F>
206where
207 F: for<'a> Fn(&mut RingBufferPostUpdateContext<'a>) -> Result<()> + Send + Sync,
208{
209 fn intercept<'a>(&self, ctx: &mut RingBufferPostUpdateContext<'a>) -> Result<()> {
210 (self.closure)(ctx)
211 }
212}
213
214pub fn ringbuffer_post_update<F>(f: F) -> ClosureRingBufferPostUpdateInterceptor<F>
215where
216 F: for<'a> Fn(&mut RingBufferPostUpdateContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
217{
218 ClosureRingBufferPostUpdateInterceptor::new(f)
219}
220
221pub struct RingBufferPreDeleteContext<'a> {
222 pub pre: &'a RingBuffer,
223}
224
225impl<'a> RingBufferPreDeleteContext<'a> {
226 pub fn new(pre: &'a RingBuffer) -> Self {
227 Self {
228 pre,
229 }
230 }
231}
232
233pub trait RingBufferPreDeleteInterceptor: Send + Sync {
234 fn intercept<'a>(&self, ctx: &mut RingBufferPreDeleteContext<'a>) -> Result<()>;
235}
236
237impl InterceptorChain<dyn RingBufferPreDeleteInterceptor + Send + Sync> {
238 pub fn execute(&self, mut ctx: RingBufferPreDeleteContext) -> Result<()> {
239 for interceptor in &self.interceptors {
240 interceptor.intercept(&mut ctx)?;
241 }
242 Ok(())
243 }
244}
245
246pub struct ClosureRingBufferPreDeleteInterceptor<F>
247where
248 F: for<'a> Fn(&mut RingBufferPreDeleteContext<'a>) -> Result<()> + Send + Sync,
249{
250 closure: F,
251}
252
253impl<F> ClosureRingBufferPreDeleteInterceptor<F>
254where
255 F: for<'a> Fn(&mut RingBufferPreDeleteContext<'a>) -> Result<()> + Send + Sync,
256{
257 pub fn new(closure: F) -> Self {
258 Self {
259 closure,
260 }
261 }
262}
263
264impl<F> Clone for ClosureRingBufferPreDeleteInterceptor<F>
265where
266 F: for<'a> Fn(&mut RingBufferPreDeleteContext<'a>) -> Result<()> + Send + Sync + Clone,
267{
268 fn clone(&self) -> Self {
269 Self {
270 closure: self.closure.clone(),
271 }
272 }
273}
274
275impl<F> RingBufferPreDeleteInterceptor for ClosureRingBufferPreDeleteInterceptor<F>
276where
277 F: for<'a> Fn(&mut RingBufferPreDeleteContext<'a>) -> Result<()> + Send + Sync,
278{
279 fn intercept<'a>(&self, ctx: &mut RingBufferPreDeleteContext<'a>) -> Result<()> {
280 (self.closure)(ctx)
281 }
282}
283
284pub fn ringbuffer_pre_delete<F>(f: F) -> ClosureRingBufferPreDeleteInterceptor<F>
285where
286 F: for<'a> Fn(&mut RingBufferPreDeleteContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
287{
288 ClosureRingBufferPreDeleteInterceptor::new(f)
289}