An open API service indexing awesome lists of open source software.

https://github.com/notapenguin0/dyn_inject

Utilities for dynamically dispatched dependency injection in Rust
https://github.com/notapenguin0/dyn_inject

Last synced: over 1 year ago
JSON representation

Utilities for dynamically dispatched dependency injection in Rust

Awesome Lists containing this project

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

```rs
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::(Bar);
// Calls Bar::foo()
registry.get_dyn::().unwrap().foo()
}
```