fix: DecisionLoader and downcast trait (#414)

This commit is contained in:
bcrevar-gorules
2025-11-21 12:49:21 +01:00
committed by GitHub
parent 938e7de505
commit 8ebc344603
4 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -28,9 +28,9 @@ zen-types = { path = "../types", version = "0.51.1" }
zen-expression = { path = "../expression", version = "0.51.1" }
zen-tmpl = { path = "../template", version = "0.51.1" }
nohash-hasher = { workspace = true }
downcast-rs = { version = "2.0", features = ["std", "sync"] }
[dev-dependencies]
chrono = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
criterion = { workspace = true, features = ["async_tokio"] }
insta = { version = "1.43", features = ["yaml", "redactions"] }
+3
View File
@@ -182,4 +182,7 @@ impl DecisionEngine {
let content = self.loader.load(key).await?;
Ok(self.create_decision(content))
}
pub fn loader(&self) -> DynamicLoader {
self.loader.clone()
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ where
impl<F, O> DecisionLoader for ClosureLoader<F>
where
F: Fn(String) -> O + Sync + Send,
F: Fn(String) -> O + Sync + Send + 'static,
O: Future<Output = LoaderResponse> + Send,
{
fn load<'a>(
+5 -3
View File
@@ -1,8 +1,8 @@
use downcast_rs::{impl_downcast, DowncastSync};
use std::fmt::Debug;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use thiserror::Error;
pub use cached::CachedLoader;
@@ -19,19 +19,21 @@ mod filesystem;
mod memory;
mod noop;
pub type DynamicLoader = Arc<dyn DecisionLoader + Send + Sync>;
pub type DynamicLoader = Arc<dyn DecisionLoader>;
pub type LoaderResult<T> = Result<T, LoaderError>;
pub type LoaderResponse = LoaderResult<Arc<DecisionContent>>;
/// Trait used for implementing a loader for decisions
pub trait DecisionLoader: Debug + Send {
pub trait DecisionLoader: Debug + Send + Sync + DowncastSync {
fn load<'a>(
&'a self,
key: &'a str,
) -> Pin<Box<dyn Future<Output = LoaderResponse> + 'a + Send>>;
}
impl_downcast!(sync DecisionLoader);
#[derive(Error, Debug)]
pub enum LoaderError {
#[error("Loader did not find item with key {0}")]