#graph #building #macro #input

forgy

Derive macro for building dependency graphs

1 unstable release

0.1.0 Jan 26, 2025

#644 in Rust patterns

Download history 98/week @ 2025-01-21 55/week @ 2025-01-28 27/week @ 2025-02-04

180 downloads per month

MIT license

8KB
152 lines

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

lib.rs:

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

Dependencies

~0.6–1MB
~23K SLoC

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy