pub mod error;
pub mod format;
pub mod impls;
pub mod source;
pub use error::FmtError;
pub use impls::{DynLoader, StaticLoader};
pub use source::MemorySource;
#[cfg(feature = "fs")]
pub use source::FileSource;
use async_trait::async_trait;
use serde::de::DeserializeOwned;
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct LoadInfo {
pub path: PathBuf,
pub format: &'static str,
}
#[derive(Debug)]
pub enum LoadResult<T> {
Ok { value: T, info: LoadInfo },
NotFound,
Invalid(FmtError),
}
pub trait PreProcess {
fn pre_process(&mut self) {}
fn set_context(&mut self, _ctx: &str) {}
}
#[cfg(feature = "validate")]
pub trait ValidateConfig: validator::Validate {
fn validate_config(&self) -> Result<(), FmtError> {
self.validate().map_err(FmtError::Validation)
}
}
#[cfg(feature = "validate")]
impl<T: validator::Validate> ValidateConfig for T {}
#[cfg(not(feature = "validate"))]
pub trait ValidateConfig {
fn validate_config(&self) -> Result<(), FmtError> {
Ok(())
}
}
#[cfg(not(feature = "validate"))]
impl<T> ValidateConfig for T {}
pub trait Format: Send + Sync {
fn extensions(&self) -> &'static [&'static str];
fn parse<T: DeserializeOwned>(&self, input: &[u8]) -> Result<T, FmtError>;
}
#[async_trait]
pub trait Source: Send + Sync {
async fn read(&self, key: &str) -> Result<Vec<u8>, FmtError>;
async fn exists(&self, key: &str) -> bool;
}