2 releases
0.1.1 | Jun 8, 2023 |
---|---|
0.1.0 | Jun 7, 2023 |
#1085 in Procedural macros
5KB
sdi
Rust statically resolved dependency injection library
Usage
provide!
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))
inject!
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))
Dependencies
~65KB