What problem does it solve?
CGP provides a structured approach to dependency injection in Rust by moving interface constraints into impl blocks and using type-level tables to map components to providers per context. This enables multiple provider implementations for the same interface and allows swapping behavior by context without changing the consumer code.
Core Features & Use Cases
- Type-level components and providers enable modular wiring that adapts to different contexts.
- DelegateComponent tables map a provider to a concrete implementation for a given context, enabling pluggable behavior.
- Blanket trait delegation and impl-side dependencies hide the wiring complexity behind clean trait interfaces.
- Typical use cases include building context-specific plug-ins, testing with mock providers, and composing complex behavior across modules.
Quick Start
Define a CGP component with #[cgp_component], supply a provider with #[cgp_provider], and wire it to a context using delegate_components! or a DelegateComponent table. Then instantiate a concrete context and call the consumer method to observe the delegated provider in action.