shepherd-rs 0.2.0

Shepherd is a resilient, non-blocking orchestrator that persistently transforms and delivers data—built for remote, compute-heavy workloads.
Documentation
//! # A module for managing configurations
//!
//! This module provides abstractions for managing composite configurations in
//! the shepherd framework. It includes traits for static and dynamic
//! configurations, allowing for flexible and scalable configuration management.
//!
//! ## Overview
//! - **Config**: Combines static and dynamic configurations.
//! - **StaticConfig**: Represents immutable configuration values.
//! - **DynamicConfig**: Represents mutable configuration values that can be
//!   updated at runtime.
//!
//! ## Usage
//! Implement the `Config` trait to define how static and dynamic
//! configurations are combined and updated.
//!
//! ## Example
//! ```rust
//! use crate::config::{Config, StaticConfig, DynamicConfig};
//!
//! struct MyConfig;
//!
//! impl Config for MyConfig {
//!     // Implementation details...
//! }
//! ```

//! A composite config that combines the static and dynamic configurations
//! for the `shepherd-rs` processing system, and provides update
//! functionality for the dynamic configuration.

pub mod inmem;

use std::error::Error;
use std::hash::Hash;

use async_trait::async_trait;
use serde::Serialize;
use serde::de::DeserializeOwned;

#[async_trait]
pub trait Config: Send + Sync {
    /// A handle to the static configuration. Could be
    /// a database connection, a file path, or any other
    /// resource that provides static configuration values.
    type StaticConfigHandle: Send;

    type KeyType: Hash + Send + Sync;
    type ValueType: Serialize + DeserializeOwned + Send + Sync + Clone;

    type Error: Error + Send + Sync;

    /// Creates a new instance of the static config.
    async fn new(handle: Self::StaticConfigHandle) -> Result<Self, Self::Error>
    where
        Self: Sized;

    /// Sets a static value in the configuration.
    async fn set(&mut self, key: Self::KeyType, value: Self::ValueType) -> Result<(), Self::Error>;

    /// Set a bulk of static values in the configuration.
    async fn set_bulk(
        &mut self,
        values: Vec<(Self::KeyType, Self::ValueType)>,
    ) -> Result<(), Self::Error>;

    /// Gets a static value from the configuration.
    async fn get(&self, key: Self::KeyType) -> Result<Self::ValueType, Self::Error>;
}