| Crates.io | supply-demand |
| lib.rs | supply-demand |
| version | 0.0.2 |
| created_at | 2025-07-09 09:37:44.174274+00 |
| updated_at | 2025-07-09 09:59:54.282564+00 |
| description | Supply-Demand - A functional dependency injection library |
| homepage | |
| repository | https://github.com/ceil-rust/supply-demand |
| max_upload_size | |
| id | 1744569 |
| size | 20,858 |
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.
async_trait support for ergonomic async/await suppliersuse supply_demand::{Supplier, Demand, Scope, SupplierRegistry};
use async_trait::async_trait;
use std::collections::HashMap;
use std::sync::Arc;
// A supplier returning i32
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); // prints "Result is 42"
}
See full documentation at docs.rs/supply-demand.
Licensed under MIT license.