| Crates.io | forgy |
| lib.rs | forgy |
| version | 0.1.0 |
| created_at | 2025-01-26 04:49:57.883622+00 |
| updated_at | 2025-01-26 04:49:57.883622+00 |
| description | Derive macro for building dependency graphs. |
| homepage | https://docs.rs/forgy |
| repository | https://github.com/shelbyd/forgy |
| max_upload_size | |
| id | 1531047 |
| size | 9,959 |
Derive macro and traits for building dependency graphs. Simple dependency injector.
use std::sync::Arc;
#[derive(forgy::Build)]
#[forgy(input = Input)]
struct Foo {
#[forgy(value = input.the_string.clone())]
from_input: String,
}
#[derive(forgy::Build)]
#[forgy(input = Input)]
struct Bar {
foo: Arc<Foo>,
}
struct Input {
the_string: String,
}
fn main() {
let mut c = forgy::Container::new(Input {
the_string: "from input".to_string(),
});
let bar: Bar = c.build();
assert_eq!(bar.foo.from_input, "from input");
let foo: Arc<Foo> = c.get();
assert_eq!(Arc::as_ptr(&bar.foo), Arc::as_ptr(&foo));
}