dyn_inject

Crates.iodyn_inject
lib.rsdyn_inject
version0.1.0
sourcesrc
created_at2023-04-23 09:56:31.686573
updated_at2023-04-23 09:56:31.686573
descriptionRust dependency injection that works with trait objects.
homepage
repositoryhttps://github.com/NotAPenguin0/dyn_inject
max_upload_size
id846454
size5,054
NotAPenguin (NotAPenguin0)

documentation

README

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()
}
Commit count: 7

cargo fmt