Crates.io | sdi |
lib.rs | sdi |
version | 0.1.1 |
source | src |
created_at | 2023-06-07 12:14:34.153923 |
updated_at | 2023-06-08 00:10:20.410803 |
description | Rust statically resolved dependency injection lib |
homepage | https://github.com/Thaumy/sdi |
repository | |
max_upload_size | |
id | 884710 |
size | 5,688 |
Rust statically resolved dependency injection library
Register an statically resolved service expression indexed by key.
use sdi::{inject, provide};
#[derive(Debug, PartialEq)]
struct A;
impl A {
pub fn new() -> A { A }
provide!(A <- A::new());
}
assert_eq!(A::new(), inject!(A))
Provide by inject is also ok.
use sdi::{inject, provide};
#[derive(Debug, PartialEq)]
struct A;
provide!(A <- A);
#[derive(Debug, PartialEq)]
struct B(A);
impl B {
pub fn new(a:A) -> B { B(a) }
provide!(B <- B::new(inject!(A)));
}
assert_eq!(B::new(A), inject!(B))
Get an statically resolved service expression by key.
use sdi::{inject, provide};
#[derive(Debug, PartialEq)]
struct A;
impl A {
pub fn new() -> A { A }
provide!(A <- A::new());
}
assert_eq!(A::new(), inject!(A))