
Generics
Dependency Injection in Rust With Traits and Generics
Rust needs no DI container. Define a trait for the dependency, take it in the constructor and wire the real types in main. Tests pass a fake instead.
8 min read
Tag
2 posts

Rust needs no DI container. Define a trait for the dependency, take it in the constructor and wire the real types in main. Tests pass a fake instead.

Depend on a trait that you own, not on a concrete client. Learn generics versus Arc dyn for wiring, when a trait is not worth it and how to keep it small.