1use std::fmt::Debug;
2use std::future::Future;
3use std::sync::Arc;
4
5use thiserror::Error;
6
7pub use cached::CachedLoader;
8pub use closure::ClosureLoader;
9pub use filesystem::{FilesystemLoader, FilesystemLoaderOptions};
10pub use memory::MemoryLoader;
11pub use noop::NoopLoader;
12
13use crate::model::DecisionContent;
14
15mod cached;
16mod closure;
17mod filesystem;
18mod memory;
19mod noop;
20
21pub type LoaderResult<T> = Result<T, LoaderError>;
22pub type LoaderResponse = LoaderResult<Arc<DecisionContent>>;
23
24pub trait DecisionLoader {
26 fn load<'a>(&'a self, key: &'a str) -> impl Future<Output = LoaderResponse> + 'a;
27}
28
29#[derive(Error, Debug)]
30pub enum LoaderError {
31 #[error("Loader did not find item with key {0}")]
32 NotFound(String),
33 #[error("Loader failed internally on key {key}: {source}.")]
34 Internal {
35 key: String,
36 #[source]
37 source: anyhow::Error,
38 },
39}