1use crate::{error::Result, exchange::Exchange};
4use async_trait::async_trait;
5use std::sync::Arc;
6
7#[async_trait]
11pub trait Processor: Send + Sync {
12 async fn process(&self, exchange: &mut Exchange) -> Result<()>;
13}
14
15pub struct FnProcessor<F>(F);
21
22impl<F> FnProcessor<F>
23where
24 F: Fn(&mut Exchange) -> Result<()> + Send + Sync + 'static,
25{
26 pub fn new(f: F) -> Arc<Self> {
27 Arc::new(Self(f))
28 }
29}
30
31#[async_trait]
32impl<F> Processor for FnProcessor<F>
33where
34 F: Fn(&mut Exchange) -> Result<()> + Send + Sync + 'static,
35{
36 async fn process(&self, exchange: &mut Exchange) -> Result<()> {
37 (self.0)(exchange)
38 }
39}
40
41pub trait Predicate: Send + Sync {
44 fn matches(&self, exchange: &Exchange) -> bool;
45}
46
47impl<F> Predicate for F
48where
49 F: Fn(&Exchange) -> bool + Send + Sync,
50{
51 fn matches(&self, exchange: &Exchange) -> bool {
52 self(exchange)
53 }
54}