mirror of
https://github.com/gorules/zen.git
synced 2026-10-04 00:02:18 +00:00
fix: DecisionLoader and downcast trait (#414)
This commit is contained in:
@@ -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"] }
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>(
|
||||
|
||||
@@ -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}")]
|
||||
|
||||
Reference in New Issue
Block a user