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
- Host: GitHub
- URL: https://github.com/notapenguin0/dyn_inject
- Owner: NotAPenguin0
- Created: 2023-04-23T09:53:36.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-09T14:12:44.000Z (about 3 years ago)
- Last Synced: 2025-02-28T14:16:12.915Z (over 1 year ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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()
}
```