dyn_inject 0.1.0

Rust dependency injection that works with trait objects.
Documentation
  • Coverage
  • 87.5%
    7 out of 8 items documented1 out of 7 items with examples
  • Size
  • Source code size: 4.74 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.29 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • NotAPenguin0/dyn_inject
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • NotAPenguin0

dyn_inject

This crates provides utilities for dependency injection in Rust, also supporting dyn Trait trait objects instead of only static, sized types.

Example

use dyn_inject::Registry;

trait Foo {
    fn foo();
}

struct Bar;

impl Foo for Bar {
    fn foo() {
        println!("Hello");
    }
}

fn main() {
    let mut registry = Registry::new();
    registry.put_dyn::<dyn Foo>(Bar);
    // Calls Bar::foo()
    registry.get_dyn::<dyn Foo>().unwrap().foo()
}