forgy 0.1.0

Derive macro for building dependency graphs.
Documentation
  • Coverage
  • 87.5%
    7 out of 8 items documented1 out of 8 items with examples
  • Size
  • Source code size: 12.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.41 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • shelbyd/forgy
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • shelbyd

forgy

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));
}