From d0bd6c8ed4142c9b872c4875c02e599b61a38083 Mon Sep 17 00:00:00 2001 From: Stepan Henek Date: Mon, 29 Jun 2020 00:11:37 +0200 Subject: [PATCH] fix: make matchers clonable --- streamson-lib/src/matcher/combinator.rs | 10 +++++----- streamson-lib/src/matcher/depth.rs | 2 +- streamson-lib/src/matcher/simple.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/streamson-lib/src/matcher/combinator.rs b/streamson-lib/src/matcher/combinator.rs index f3a4837..3aa123a 100644 --- a/streamson-lib/src/matcher/combinator.rs +++ b/streamson-lib/src/matcher/combinator.rs @@ -2,9 +2,9 @@ use super::MatchMaker; use std::ops; +use std::sync::Arc; -#[derive(Debug)] - +#[derive(Debug, Clone)] /// Combines several matches together /// /// It implements normal boolean algebra @@ -13,7 +13,7 @@ use std::ops; /// * `comb1 | comb2` at least one should pass pub enum Combinator { /// Represents the actual underlying matcher - Matcher(Box), + Matcher(Arc), /// Negates the expression Not(Box), /// Both expressions should be valid @@ -38,8 +38,8 @@ impl Combinator { /// /// # Arguments /// * `matcher` - matcher to be wrapped - pub fn new(matcher: impl MatchMaker + 'static) -> Self { - Self::Matcher(Box::new(matcher)) + pub fn new(matcher: impl MatchMaker + 'static + Sync) -> Self { + Self::Matcher(Arc::new(matcher)) } } diff --git a/streamson-lib/src/matcher/depth.rs b/streamson-lib/src/matcher/depth.rs index 42debae..8129122 100644 --- a/streamson-lib/src/matcher/depth.rs +++ b/streamson-lib/src/matcher/depth.rs @@ -5,7 +5,7 @@ use super::MatchMaker; /// Based on actual path depth /// /// Path is matched when path depth is higher or equal min and lower or equal max (optional) -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone)] pub struct Depth { min: usize, max: Option, diff --git a/streamson-lib/src/matcher/simple.rs b/streamson-lib/src/matcher/simple.rs index 07ae4bb..8b527bd 100644 --- a/streamson-lib/src/matcher/simple.rs +++ b/streamson-lib/src/matcher/simple.rs @@ -9,7 +9,7 @@ use std::str::FromStr; /// It matches {"People"}[0]{"Height"} - height of the first person /// It matches {"People"}[]{"Height"} - matches the height of all people /// It matches {"People"}[0]{} - matches all attributes of the first person -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone)] pub struct Simple { path_expr: String, }