Skip to content

Commit b7bece8

Browse files
committed
Support cloning an execution context
1 parent 118d93b commit b7bece8

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ backtrace = "0.3"
2020
cfg-if = "1"
2121
cidr = { version = "0.2", features = ["serde"] }
2222
criterion = "0.5"
23+
dyn-clone = "1.0.20"
2324
fnv = "1.0.6"
2425
getrandom = { version = "0.3" }
2526
indoc = "2"

engine/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ harness = false
2323
backtrace.workspace = true
2424
cfg-if.workspace = true
2525
cidr.workspace = true
26+
dyn-clone.workspace = true
2627
fnv.workspace = true
2728
memmem.workspace = true
2829
rand.workspace = true

engine/src/execution_context.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ impl<'e, U> ExecutionContext<'e, U> {
224224
ExecutionContextGuard::new(self, user_data)
225225
}
226226

227+
/// Clone the current [`ExecutionContext`] into a new one.
228+
#[inline]
229+
pub fn clone_with<T>(&self, user_data: T) -> ExecutionContext<'e, T> {
230+
ExecutionContext {
231+
scheme: self.scheme.clone(),
232+
values: self.values.clone(),
233+
list_matchers: self.list_matchers.clone(),
234+
user_data,
235+
}
236+
}
237+
227238
/// Clears the execution context, removing all values and lists
228239
/// while retaining the allocated memory.
229240
#[inline]

engine/src/list_matcher.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::LhsValue;
22
use crate::Type;
3+
use dyn_clone::DynClone;
34
use serde_json::Value;
45
use std::any::Any;
56
use std::fmt::Debug;
@@ -58,7 +59,7 @@ impl<T: PartialEq + Any> DynPartialEq for T {
5859
}
5960

6061
/// Implement this Trait to match a given `LhsValue` against a list.
61-
pub trait ListMatcher: AsAny + Debug + DynPartialEq + Send + Sync + 'static {
62+
pub trait ListMatcher: AsAny + Debug + DynClone + DynPartialEq + Send + Sync + 'static {
6263
/// Returns true if `val` is in the given list.
6364
fn match_value(&self, list_name: &str, val: &LhsValue<'_>) -> bool;
6465

@@ -69,6 +70,8 @@ pub trait ListMatcher: AsAny + Debug + DynPartialEq + Send + Sync + 'static {
6970
fn clear(&mut self);
7071
}
7172

73+
dyn_clone::clone_trait_object!(ListMatcher);
74+
7275
impl PartialEq for dyn ListMatcher {
7376
#[inline]
7477
fn eq(&self, other: &dyn ListMatcher) -> bool {

0 commit comments

Comments
 (0)