supply-demand
A flexible, async-ready dependency injection and supply/demand orchestration library for Rust.
Inspired by IoC/DI patterns, supports runtime-typed supplier registries and dynamic dependency graphs.

Features
- Register arbitrary async/sync suppliers by type key
- Type-erased registry for heterogeneous dependencies
- Local override and dynamic graph composition
async_trait support for ergonomic async/await suppliers
Example
use supply_demand::{Supplier, ErasedSupplier, Demand, Scope, SupplierRegistry};
use async_trait::async_trait;
use std::collections::HashMap;
use std::sync::Arc;
struct ValueASupplier;
#[async_trait]
impl Supplier for ValueASupplier {
type Input = ();
type Output = i32;
async fn supply(&self, _input: (), _scope: Arc<Scope>) -> i32 {
42
}
}
#[tokio::main]
async fn main() {
let mut registry: SupplierRegistry = HashMap::new();
registry.insert("valueA".to_string(), Arc::new(ValueASupplier));
let scope = Arc::new(Scope {
registry: Arc::new(registry),
});
let demand = Demand { type_: "valueA".to_string(), override_suppliers: None };
let result: i32 = scope.demand(demand, Box::new(())).await;
println!("Result is {}", result); }
Documentation
See full documentation at docs.rs/supply-demand.
License
Licensed under MIT license.